接上一篇: VirtualBox安装CentOS7的网络配置(Host Only+NAT方式)
目录
2. set up the stable repository.
6. 通过运行hello-world (因不可描述原因,镜像地址不可用)
1. 直接设置 –registry-mirror 参数,仅对当前的命令有效
环境说明
系统 | Windows7 |
Oracle VM VirtualBox | 5.2.18 |
CentOS | CentOS-7-x86_64-Minimal-1810.i |
Docker | 18.09.6 |
环境准备
docker:https://www.docker.com/
docker文档:https://docs.docker.com/
docker安装:https://docs.docker.com/install/
安装
参考官方文档:
1. Install required packages.
[root@localhost ~]# yum install -y yum-utils
[root@localhost ~]# yum install -y device-mapper-persistent-data
[root@localhost ~]# yum install -y lvm2
2. set up the stable repository.
[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3. 安装最新版Docker CE和containerd
[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io
4. 启动Docker,并加入开机启动。
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
5. 验证是否安装成功
[root@localhost ~]# docker version
Client:
Version: 18.09.6
API version: 1.39
Go version: go1.10.8
Git commit: 481bc77156
Built: Sat May 4 02:34:58 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.6
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 02:02:43 2019
OS/Arch: linux/amd64
Experimental: false
[root@localhost ~]#
6. 通过运行hello-world
(因不可描述原因,镜像地址不可用)
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'
7. 修改docker镜像地址为阿里云加速地址
[root@localhost docker]# vi /etc/docker/daemon.json
{"registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]}
[root@localhost docker]# systemctl restart docker.service
[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@localhost docker]#
附:镜像地址修改
1. 直接设置 –registry-mirror 参数,仅对当前的命令有效
docker run hello-world --registry-mirror=https://docker.mirrors.ustc.edu.cn
2. 支持 systemctl 的系统
进入到路径/lib/systemd/system下,直接vim docker.service 进入编辑该配置文件,然后找到ExecStart这项
systemctl daemon-reload
systemctl restart docker
systemctl status docker
docker system info
3. json 配置文件的方式
默认为 /etc/docker/daemon.json,非默认路径需要修改 dockerd 的 –config-file,在该文件中加入如下内容:
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}