CentOS 7 安裝 Docker 應用程式容器教程

來源:互聯網
上載者:User

本文我們來看看如何在 CentOS 7 上安裝 Docker。Docker就像是輕量級的虛擬機器,可以讓建立和管理 Linux 容器變得簡單。並且可以以毫秒級的速度來啟動或停止。Docker 協助系統管理員和程式員在容器中開發應用程式,並且可以擴充到成千上萬的節點。

  容器和 VM(虛擬機器)的主要區別是,容器提供了基於進程的隔離,而虛擬機器提供了資源的完全隔離。虛擬機器可能需要一分鐘來啟動,而容器只需要一秒鐘或更短。容器使用宿主作業系統的核心,而虛擬機器使用獨立的核心。

  Docker 的局限性之一是,它只能用在 64 位元的作業系統上。


在這篇文章中我們將討論如何在 CentOS 7.x 中安裝 docker。

  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 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 容器已經被啟動,並且我們得到了 bash 提示符。在 docker 命令中我們使用了 “-i 捕獲標準輸入輸出”和 “-t 分配一個終端或控制台”選項。若要斷開與容器的串連,輸入 exit。
    
[root@cd05639b3f5c /]# cat /<span style="width: auto; height: auto; float: none;" id="0_nwp"><a style="text-decoration: none;" mpid="0" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?c=news&cf=1001&ch=0&di=128&fv=15&jk=3f02a9bcc6ed33e5&k=etc&k0=etc&kdi0=0&luki=2&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=e533edc6bca9023f&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F5556%2Ehtml&urlid=0" id="0_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">etc</span></a></span>/redhat-release
CentOS Linux release 7.0.1406 (Core)
[root@cd05639b3f5c /]# exit
exit
[root@localhost ~]#

  我們還可以搜尋基於 Fedora 和 Ubuntu 作業系統的容器。

[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

顯示當前正在運行容器的列表

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.