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