https://linux.cn/article-4340-1.htmlhtml
Docker 軟件包已經包括在默認的 CentOS-Extras 軟件源裏。所以想要安裝 docker,只須要運行下面的 yum 命令:python
- [root@localhost ~]# yum install docker
安裝完成後,使用下面的命令來啓動 docker 服務,並將其設置爲開機啓動:linux
- [root@localhost ~]# service docker start
- [root@localhost ~]# chkconfig docker on
(LCTT 譯註:此處採用了舊式的 sysv 語法,如採用CentOS 7中支持的新式 systemd 語法,以下:docker
- [root@localhost ~]# systemctl start docker.service
- [root@localhost ~]# systemctl enable docker.service
)ubuntu
下載官方的 CentOS 鏡像到本地 (LCTT 譯註:因爲 Docker 被牆 :-< ,因此請使用 http://docker.cn 的鏡像,感謝 @馬全一 的鏡像。 )centos
- [root@localhost ~]# docker pull centos
- Pulling repository centos
- 192178b11d36: Download complete
- 70441cac1ed5: Download complete
- ae0c2d0bdc10: Download complete
- 511136ea3c5a: Download complete
- 5b12ef8fd570: Download complete
確認 CentOS 鏡像已經被獲取:bash
- [root@localhost ~]# docker images centos
- REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
- centos centos5 192178b11d36 2 weeks ago 466.9 MB
- centos centos6 70441cac1ed5 2 weeks ago 215.8 MB
- centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
- centos latest ae0c2d0bdc10 2 weeks ago 224 MB
運行一個 Docker 容器:python2.7
- [root@localhost ~]# docker run -i -t centos /bin/bash
- [root@dbf66395436d /]#
咱們能夠看到,CentOS 容器已經被啓動,而且咱們獲得了 bash 提示符。在 docker 命令中咱們使用了 「-i 捕獲標準輸入輸出」和 「-t 分配一個終端或控制檯」選項。若要斷開與容器的鏈接,輸入 exit。ui
- [root@cd05639b3f5c /]# cat /etc/redhat-release
- CentOS Linux release 7.0.1406 (Core)
- [root@cd05639b3f5c /]# exit
- exit
- [root@localhost ~]#
咱們還能夠搜索基於 Fedora 和 Ubuntu 操做系統的容器。centos7
- [root@localhost ~]# docker search ubuntu
- [root@localhost ~]# docker search fedora
顯示當前正在運行容器的列表
雖然很簡單,仍是有URL確認,x權限設定等須要作,若是使用pip進行安裝雖然看似繞遠,實質上也是繞遠,安裝來一看吧。CentOS上須要先行安裝yum的一個額外的包,這個包裏面纔有python-pip,缺省的沒有。
[root@host32 ~]# yum -y install epel-release
[root@host32 ~]# yum -y install python-pip
確認版本
[root@host32 ~]# pip --version
pip 7.1.0 from /usr/lib/python2.7/site-packages (python 2.7)
接下來就是安裝docker-compose[root@host32 ~]# pip install docker-compose
[root@bogon bin]# docker-compose version
docker-compose version 1.15.0, build e12f3b9
docker-py version: 2.4.2
CPython version: 2.7.5