一、安装
使用yum安装docker,但是yum源不是最新的。这里用github上面最新的来安装
首先下载最新的deb/rpm install:
[root@iZ94b93cemmZ ~]#curl -fsSL https://get.docker.com/ | sh
这个过程可能出现timeout,执行多几遍就好了。然后安装
[root@iZ94b93cemmZ ~]#yum install docker-engine
二、查看docker
输入docker version发现没能启动
[root@iZ94b93cemmZ ~#docker version
Client:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Wed Apr 27 00:34:42 2016
OS/Arch: linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
三、解决错误
查看服务启动日志发现错误。
[root@iZ94b93cemmZ ~]#service docker status
Redirecting to /bin/systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2016-05-04 10:11:26 CST; 58min ago
Docs: https://docs.docker.com
Main PID: 25800 (code=exited, status=1/FAILURE)
May 04 10:11:26 iZ94b93cemmZ docker[25800]: time="2016-05-04T10:11:26.356614155+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
May 04 10:11:26 iZ94b93cemmZ docker[25800]: time="2016-05-04T10:11:26.378033501+08:00" level=info msg="Firewalld running: false"
May 04 10:11:26 iZ94b93cemmZ docker[25800]: time="2016-05-04T10:11:26.494923635+08:00" level=fatal msg="Error starting daemon: Error initializing network controller: Error creating default..."
May 04 10:11:26 iZ94b93cemmZ systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
May 04 10:11:26 iZ94b93cemmZ docker[25800]: time="2016-05-04T10:11:26+08:00" level=info msg="stopping containerd after receiving terminated"
May 04 10:11:26 iZ94b93cemmZ systemd[1]: Failed to start Docker Application Container Engine.
May 04 10:11:26 iZ94b93cemmZ systemd[1]: Unit docker.service entered failed state.
May 04 10:11:26 iZ94b93cemmZ systemd[1]: docker.service failed.
May 04 10:14:22 iZ94b93cemmZ systemd[1]: Stopped Docker Application Container Engine.
May 04 10:20:23 iZ94b93cemmZ systemd[1]: Stopped Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
其中关键就是这句,在网上查了很多资料最后发现是说,阿里云的内网IP被占用了没有可用的内网IP给到docker使用。
"Error starting daemon: Error initializing network controller: Error creating default..."
新建docker0文件,编辑完退出vi。
[root@iZ94b93cemmZ /etc/sysconfig/network-scripts]#vi docker0
DEVICE=docker0
ONBOOT=yes
BOOTPROTO=static
GATEWAY=10.116.103.247
IPADDR=10.116.96.148
NETMASK=255.255.248.0
TYPE='Bridge'
重启docker0和重启网关
[root@iZ94b93cemmZ /etc/sysconfig/network-scripts]#ifup docker0
[root@iZ94b93cemmZ /etc/sysconfig/network-scripts]#service network restart
重启docker
[root@iZ94b93cemmZ /etc/sysconfig/network-scripts]#service docker restart
再次查看docker version、docker ps 、docker images一切正常
[root@iZ94b93cemmZ /etc/sysconfig/network-scripts]#docker version
Client:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Wed Apr 27 00:34:42 2016
OS/Arch: linux/amd64
Server:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Wed Apr 27 00:34:42 2016
OS/Arch: linux/amd64
[root@iZ94b93cemmZ /etc/sysconfig/network-scripts]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@iZ94b93cemmZ /etc/sysconfig/network-scripts]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
设置开启启动
systemctl enable docker.service
四、使用阿里Docker镜像下载
首先查看一下network是不是正常启动。主要看100.64.0.0这个内网和docker0的启动起来。
[root@iZ94b93cemmZ ~]#netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 120.25.255.247 0.0.0.0 UG 0 0 0 eth1
10.0.0.0 10.116.103.247 255.0.0.0 UG 0 0 0 eth0
10.116.96.0 0.0.0.0 255.255.248.0 U 0 0 0 docker0
10.116.96.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0
100.64.0.0 10.116.103.247 255.192.0.0 UG 0 0 0 eth0
120.25.252.0 0.0.0.0 255.255.252.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.16.0.0 10.116.103.247 255.240.0.0 UG 0 0 0 eth0
192.168.0.0 10.116.103.247 255.255.0.0 UG 0 0 0 eth0
然后执行以下阿里官网的教程,就可以正常下载镜像了。因为docker的启动使用的/lib/systemd/system/docker.service的配置,把/etc/systemd/system/docker.service重新替换掉/etc/systemd/system/docker.service没错重启服务器就不用跑下面这段。
# 系统要求 CentOS 7 以上,Docker 1.9 以上。
sudo cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.service
sudo sed -i "s|ExecStart=/usr/bin/docker daemon|ExecStart=/usr/bin/docker daemon --registry-mirror=https://cdlkj8kf.mirror.aliyuncs.com|g" /etc/systemd/system/docker.service
sudo systemctl daemon-reload
sudo service docker restart
[root@iZ94b93cemmZ ~]#docker pull redis
Using default tag: latest
latest: Pulling from library/redis
a3ed95caeb02: Pull complete
f1808fdbcba0: Pull complete
1712088b6004: Pull complete
3526e56c913b: Pull complete
622a4e300666: Pull complete
f7ca8b8da956: Pull complete
c74d95cebdf1: Pull complete
48d4b6fc6e07: Pull complete
Digest: sha256:68524efa50a33d595d7484de3939a476b38667c7b4789f193761899ca125d016
Status: Downloaded newer image for redis:latest
[root@iZ94b93cemmZ ~]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
maven 3.3.3-jdk-7 1e0ffd228d93 7 days ago 597 MB
jenkins latest 518ba3eee586 12 days ago 709.9 MB
redis latest 0f0e96f1f267 13 days ago 177.4 MB
centos 7.1.1503 30e55721fefe 6 months ago 212.1 MB
然后修改启动脚本了rc.local添加了
#启动docker network
ifup docker0
#重启docker
systemctl daemon-reload
service docker restart
#重启network
service network restart
这样就每次重启后都可以直接使用阿里镜像下载了。
参考文章:
阿里云Docker镜像:https://dev.aliyun.com/search.html
Docker Github项目:https://github.com/docker/docker
Docker官方文档:https://docs.docker.com/engine/installation/
阿里云论坛:https://bbs.aliyun.com/read/167185.html?pos=10