1、安裝html
使用yum安裝docker,可是yum源不是最新的。這裏用github上面最新的來安裝linux
首先下載最新的deb/rpm install: git
[root@iZ94b93cemmZ ~]#curl -fsSL https://get.docker.com/ | sh
這個過程可能出現timeout,執行多幾遍就行了。而後安裝github
[root@iZ94b93cemmZ ~]#yum install docker-engine
2、查看dockerredis
輸入docker version發現沒能啓動docker
[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?
3、解決錯誤centos
查看服務啓動日誌發現錯誤。服務器
[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使用。app
"Error starting daemon: Error initializing network controller: Error creating default..."
新建docker0文件,編輯完退出vi。curl
[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
4、使用阿里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