如何在 CentOS 7 上安裝 Docker
Docker 是一個開源工具,它可以讓創(chuàng)建和管理 Linux 容器變得簡單。容器就像是輕量級的虛擬機,并且可以以毫秒級的速度來啟動或停止。Docker 幫助系統(tǒng)管理員和程序員在容器中開發(fā)應(yīng)用程序,并且可以擴展到成千上萬的節(jié)點。
容器和 VM(虛擬機)的主要區(qū)別是,容器提供了基于進程的隔離,而虛擬機提供了資源的完全隔離。虛擬機可能需要一分鐘來啟動,而容器只需要一秒鐘或更短。容器使用宿主操作系統(tǒng)的內(nèi)核,而虛擬機使用獨立的內(nèi)核。
Docker 的局限性之一是,它只能用在 64 位的操作系統(tǒng)上。
在這篇文章中我們將討論如何在 CentOS 7.x 中安裝 docker。
CentOS 7 中 Docker 的安裝
Docker 軟件包已經(jīng)包括在默認的 CentOS-Extras 軟件源里。因此想要安裝 docker,只需要運行下面的 yum 命令:
- [root@localhost ~]# yum install docker
啟動 Docker 服務(wù)
安裝完成后,使用下面的命令來啟動 docker 服務(wù),并將其設(shè)置為開機啟動:
- [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 鏡像已經(jīng)被獲?。?/strong>
- [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 容器:
- [root@localhost ~]# docker run -i -t centos /bin/bash
- [root@dbf66395436d /]#
我們可以看到,CentOS 容器已經(jīng)被啟動,并且我們得到了 bash 提示符。在 docker 命令中我們使用了 “-i 捕獲標(biāo)準(zhǔn)輸入輸出”和 “-t 分配一個終端或控制臺”選項。若要斷開與容器的連接,輸入 exit。
- [root@cd05639b3f5c /]# cat /etc/redhat-release
- CentOS Linux release 7.0.1406 (Core)
- [root@cd05639b3f5c /]# exit
- exit
- [root@localhost ~]#
我們還可以搜索基于 Fedora 和 Ubuntu 操作系統(tǒng)的容器。
- [root@localhost ~]# docker search ubuntu
- [root@localhost ~]# docker search fedora
顯示當(dāng)前正在運行容器的列表
via: http://www.linuxtechi.com/install-docker-on-centos-7/
作者:Pradeep Kumar 譯者:felixonmars 校對:wxy