1.在中国安装docker请注意
这里面需要注意的是,在参考官方安装文档配置 Linux 源的时候,如果是国内服务器,要将其中的 https://download.docker.com/linux/ 替换为 https://mirrors.aliyun.com/docker-ce/linux/。
比如,文档如果要求执行下面的命令:
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
那么就替换为:
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
这样安装 Docker 就会使用阿里云的软件源,而不需要翻墙了。(注:这不是加速器,不要搞错了,加速器依旧需要配!)
2.准备工作:
2.1备份centos的基本获取源
[root@CentOS1611 yum.repos.d]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup1
[root@CentOS1611 yum.repos.d]# ls
CentOS-Base.repo.backup1 CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
2.2将centos的基本获取源获取源改为阿里的源
[root@CentOS1611 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2017-10-19 13:48:05-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 150.138.211.2, 150.138.211.6, 150.138.211.5, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|150.138.211.2|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2573 (2.5K) [application/octet-stream]
正在保存至: "/etc/yum.repos.d/CentOS-Base.repo"
100%[===============================================================================================>] 2,573 --.-K/s 用时 0s
2017-10-19 13:48:13 (144 MB/s) - 已保存 "/etc/yum.repos.d/CentOS-Base.repo" [2573/2573])
2.3确保CentOS-Media.repo使其为不生效:
enabled=0 表示禁用本地YUM源,使用网络源。
[root@CentOS1611 yum.repos.d]# more CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[root@CentOS1611 yum.repos.d]# more CentOS-Media.repo
# CentOS-Media.repo
#
# This repo can be used with mounted DVD media, verify the mount point for
# CentOS-7. You can use this repo and yum to install items directly off the
# DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
# yum --enablerepo=c7-media [command]
#
# or for ONLY the media repo, do this:
#
# yum --disablerepo=\* --enablerepo=c7-media [command]
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@CentOS1611 yum.repos.d]# yum search dock*
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
警告:没有匹配 dock* 的软件包
No matches found
[root@CentOS1611 yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@CentOS1611 yum.repos.d]# cd /var/cache/yum
[root@CentOS1611 yum]# ls
x86_64
2.4卸载老版本docker
[root@CentOS1611 packages]# yum list installed | grep docker
docker.x86_64 2:1.12.6-55.gitc4618fb.el7.centos
docker-client.x86_64 2:1.12.6-55.gitc4618fb.el7.centos
docker-common.x86_64 2:1.12.6-55.gitc4618fb.el7.centos
[root@CentOS1611 packages]# sudo yum -y remove docker.x86_64 docker-client.x86_64 docker-common.x86_64
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker.x86_64.2.1.12.6-55.gitc4618fb.el7.centos 将被 删除
---> 软件包 docker-client.x86_64.2.1.12.6-55.gitc4618fb.el7.centos 将被 删除
---> 软件包 docker-common.x86_64.2.1.12.6-55.gitc4618fb.el7.centos 将被 删除
--> 解决依赖关系完成
base/7/x86_64 | 3.6 kB 00:00:00
base/7/x86_64/group_gz | 156 kB 00:00:00
base/7/x86_64/primary_db | 5.7 MB 00:00:10
extras/7/x86_64 | 3.4 kB 00:00:00
extras/7/x86_64/primary_db | 110 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 2.7 MB 00:00:05
依赖关系解决
=========================================================================================================================================
Package 架构 版本 源 大小
=========================================================================================================================================
正在删除:
docker x86_64 2:1.12.6-55.gitc4618fb.el7.centos @extras 52 M
docker-client x86_64 2:1.12.6-55.gitc4618fb.el7.centos @extras 11 M
docker-common x86_64 2:1.12.6-55.gitc4618fb.el7.centos @extras 4.0 k
事务概要
=========================================================================================================================================
移除 3 软件包
安装大小:63 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : 2:docker-1.12.6-55.gitc4618fb.el7.centos.x86_64 1/3
正在删除 : 2:docker-client-1.12.6-55.gitc4618fb.el7.centos.x86_64 2/3
正在删除 : 2:docker-common-1.12.6-55.gitc4618fb.el7.centos.x86_64 3/3
验证中 : 2:docker-client-1.12.6-55.gitc4618fb.el7.centos.x86_64 1/3
验证中 : 2:docker-common-1.12.6-55.gitc4618fb.el7.centos.x86_64 2/3
验证中 : 2:docker-1.12.6-55.gitc4618fb.el7.centos.x86_64 3/3
删除:
docker.x86_64 2:1.12.6-55.gitc4618fb.el7.centos docker-client.x86_64 2:1.12.6-55.gitc4618fb.el7.centos
docker-common.x86_64 2:1.12.6-55.gitc4618fb.el7.centos
完毕!
[root@CentOS1611 packages]# yum remove container-selinux-1.12.5-14.el7.centos.x86_64
已加载插件:fastestmirror, langpacks
参数 container-selinux-1.12.5-14.el7.centos.x86_64 没有匹配
不删除任何软件包
[root@CentOS1611 packages]# yum remove container-selinux-1.12.5-14.el7.centos.x86_6
已加载插件:fastestmirror, langpacks
参数 container-selinux-1.12.5-14.el7.centos.x86_6 没有匹配
不删除任何软件包
[root@CentOS1611 packages]# yum remove docker*
已加载插件:fastestmirror, langpacks
参数 docker* 没有匹配
不删除任何软件包
[root@CentOS1611 packages]# rm -rf /var/lib/docker
3.重新安装CE的最新版本
3.1安装必备的YUM管理工具包
Install required packages. yum-utils provides the yum-config-manager utility, anddevice-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
3.2设置仓库
[root@CentOS1611 packages]# sudo yum-config-manager \--add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
3.3可选步骤
Optional: Enable the edge and test repositories. These repositories are included in thedocker.repo file above but are disabled by default. You can enable them alongside the stable repository.
$ sudo yum-config-manager --enable docker-ce-edge
$ sudo yum-config-manager --enable docker-ce-test
You can disable the edge or test repository by running the yum-config-manager command with the--disable flag. To re-enable it, use the --enable flag. The following command disables the edgerepository.
$ sudo yum-config-manager --disable docker-ce-edge
Note: Starting with Docker 17.06, stable releases are also pushed to the edge and testrepositories.
3.4Update the yum package index. 更新软件缓存
sudo yum makecache fast |
3.5安装docker-ce最新版本
[root@CentOS1611 packages]# sudo yum install docker-ce
已加载插件:fastestmirror, langpacks
docker-ce-stable | 2.9 kB 00:00:00
docker-ce-stable/x86_64/primary_db | 8.5 kB 00:00:00
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.0.17.06.2.ce-1.el7.centos 将被 安装
--> 解决依赖关系完成
依赖关系解决
=========================================================================================================================================
Package 架构 版本 源 大小
=========================================================================================================================================
正在安装:
docker-ce x86_64 17.06.2.ce-1.el7.centos docker-ce-stable 21 M
事务概要
=========================================================================================================================================
安装 1 软件包
总下载量:21 M
安装大小:74 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-17.06.2.ce-1.el7.centos.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY
docker-ce-17.06.2.ce-1.el7.centos.x86_64.rpm 的公钥尚未安装
docker-ce-17.06.2.ce-1.el7.centos.x86_64.rpm | 21 MB 00:00:41
从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
用户ID : "Docker Release (CE rpm) <docker@docker.com>"
指纹 : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
来自 : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : docker-ce-17.06.2.ce-1.el7.centos.x86_64 1/1
验证中 : docker-ce-17.06.2.ce-1.el7.centos.x86_64 1/1
已安装:
docker-ce.x86_64 0:17.06.2.ce-1.el7.centos
完毕!
[root@CentOS1611 packages]#
3.6Start Docker
- $ sudo systemctl start docker
[root@CentOS1611 packages]# sudo systemctl start docker
[root@CentOS1611 packages]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 四 2017-10-19 14:34:06 CST; 10s ago
Docs: https://docs.docker.com
Main PID: 5269 (dockerd)
Memory: 18.8M
CGroup: /system.slice/docker.service
├─5269 /usr/bin/dockerd
└─5281 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/contain...
10月 19 14:34:05 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:05.330769701+08:00" level=info msg="libcontainerd: new containerd process, pid: 5281"
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.333118817+08:00" level=warning msg="failed to rename /var/lib/docker/tmp for background deletion: rename /...nchronously"
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.365911634+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.366529014+08:00" level=info msg="Loading containers: start."
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.500498207+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Da... IP address"
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.543668843+08:00" level=info msg="Loading containers: done."
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.555413898+08:00" level=info msg="Daemon has completed initialization"
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.555476333+08:00" level=info msg="Docker daemon" commit=cec0b72 graphdriver=overlay version=17.06.2-ce
10月 19 14:34:06 CentOS1611 dockerd[5269]: time="2017-10-19T14:34:06.567589763+08:00" level=info msg="API listen on /var/run/docker.sock"
10月 19 14:34:06 CentOS1611 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@CentOS1611 packages]#
Verify that docker is installed correctly by running the hello-world image.
$ sudo docker run hello-world
[root@CentOS1611 packages]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
5b0f327be733: Pull complete
Digest: sha256:07d5f7800dfe37b8c2196c7b1c524c33808ce2e0f74e7aa00e603295ca9a0972
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.
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
[root@CentOS1611 packages]#
3.7Start the docker daemon at boot
Configure the Docker daemon to start automatically when the host starts:
$ sudo systemctl enable docker
[root@CentOS1611 packages]# sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@CentOS1611 packages]#
4.查看运行的docker和container信息
[root@CentOS1611 packages]# docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 17.06.2-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 7.796GiB
Name: CentOS1611
ID: 7G42:UGAK:QTES:TOTH:6LWO:5GTC:4EE3:IYUT:NQ7J:XMBA:74RX:62ID
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
[root@CentOS1611 packages]#