CentOS 7 中 Docker 的安裝
Docker 軟件包已經包括在默認的 CentOS-Extras 軟件源裏。因此想要安裝 docker,只需要運行下面的 yum 命令:
- [root@localhost ~]# yum install docker
啓動 Docker 服務
安裝完成後,使用下面的命令來啓動 docker 服務,並將其設置爲開機啓動:
- [root@localhost ~]# service docker start
- [root@localhost ~]# chkconfig docker on
(LCTT 譯註:此處採用了舊式的 sysv 語法,如採用CentOS 7中支持的新式 systemd 語法,如下:
- [root@localhost ~]# systemctl start docker.service
- [root@localhost ~]# systemctl enable docker.service
)
下載官方的 CentOS 鏡像到本地 (LCTT 譯註:由於 Docker 被牆 :-< ,所以請使用 http://docker.cn 的鏡像,感謝 @馬全一 的鏡像。 )
- [root@localhost ~]# docker pull centos
- Pulling repository centos
- 192178b11d36:Download complete
- 70441cac1ed5:Download complete
- ae0c2d0bdc10:Download complete
- 511136ea3c5a:Download complete
- 5b12ef8fd570:Download complete
確認 CentOS 鏡像已經被獲取:
- [root@localhost ~]# docker images centos
- REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
- centos centos5 192178b11d362 weeks ago 466.9 MB
- centos centos6 70441cac1ed52 weeks ago 215.8 MB
- centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
- centos latest ae0c2d0bdc10 2 weeks ago 224 MB
運行一個 Docker 容器:
- [root@localhost ~]# docker run -i -t centos /bin/bash
- [root@dbf66395436d /]#
我們可以看到,CentOS 容器已經被啓動,並且我們得到了 bash 提示符。在 docker 命令中我們使用了 “-i 捕獲標準輸入輸出”和 “-t 分配一個終端或控制檯”選項。若要斷開與容器的連接,輸入 exit。
- [root@cd05639b3f5c /]# cat /etc/RedHat-release
- CentOSLinux release 7.0.1406(Core)
- [root@cd05639b3f5c /]#exit
- exit
- [root@localhost ~]#
我們還可以搜索基於 Fedora 和 Ubuntu 操作系統的容器。
- [root@localhost ~]# docker search ubuntu
- [root@localhost ~]# docker search fedora
顯示當前正在運行容器的列表
一個大坑:
Cannot connect to the Docker daemon. Is the docker daemon running on this host docker version 只要client看不到server ,啓動報錯如上。 重啓後解決》。