服务计算——docker实践

1.安装Docker

首先按照网上的教程安装好Docker
开始安装
由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本:

$ sudo apt-get remove docker docker-engine docker-ce docker.io

更新apt包索引:

$ sudo apt-get update

安装以下包以使apt可以通过HTTPS使用存储库(repository):

$ sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

添加Docker官方的GPG密钥:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

使用下面的命令来设置stable存储库:

$ sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

再更新一下apt包索引:

$ sudo apt-get update

安装最新版本的Docker CE:

$ sudo apt-get install -y docker-ce

验证是否已经安装
在这里插入图片描述

运行第一个容器

运行镜像:
在这里插入图片描述

2.Docker 基本操作

运行镜像
在这里插入图片描述
显示本地镜像库内容
在这里插入图片描述
显示运行中容器
在这里插入图片描述
显示所有容器(包含已中止)
在这里插入图片描述

3.MySQL与容器化

构建docker镜像练习

创建文件并录入

mkdir mydock && cd mydock
mydock]# vi dockerfile
在这里插入图片描述

构建镜像
在这里插入图片描述
运行镜像
在这里插入图片描述

MySQL

拉取 MySQL 镜像
在这里插入图片描述
使用MySQL容器

  • 启动服务器
    在这里插入图片描述
  • 启动 MySQL 客户端
    在这里插入图片描述
  • 基本操作
    在这里插入图片描述
    使用MySQL容器(挂载卷保存db)
    在这里插入图片描述
    在这里插入图片描述
    创建卷并挂载
    在这里插入图片描述
    启动客户端容器链接服务器
    在这里插入图片描述
    在这里插入图片描述

4.Docker仓库

按照官方教程.进行操作:

Run a local registry

Use a command like the following to start the registry container:
在这里插入图片描述

Copy an image from Docker Hub to your registry

1.Pull the ubuntu:16.04 image from Docker Hub.

$ docker pull ubuntu:16.04

在这里插入图片描述

2.Tag the image as localhost:5000/my-ubuntu. This creates an additional tag for the existing image. When the first part of the tag is a hostname and port, Docker interprets this as the location of a registry, when pushing.

$ docker tag ubuntu:16.04 localhost:5000/my-ubuntu

在这里插入图片描述

3.Push the image to the local registry running at localhost:5000:

$ docker push localhost:5000/my-ubuntu

在这里插入图片描述
4.Remove the locally-cached ubuntu:16.04 and localhost:5000/my-ubuntu images, so that you can test pulling the image from your registry. This does not remove the localhost:5000/my-ubuntu image from your registry.

$ docker image remove ubuntu:16.04
$ docker image remove localhost:5000/my-ubuntu

在这里插入图片描述
5.Pull the localhost:5000/my-ubuntu image from your local registry.

$ docker pull localhost:5000/my-ubuntu

在这里插入图片描述

Stop a local registry

To stop the registry, use the same docker container stop command as with any other container.

$ docker container stop registry

To remove the container, use docker container rm.

$ docker container stop registry && docker container rm -v registry

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值