CentOS 7 中 Docker 的安裝


CentOS 7 中 Docker 的安裝

Docker 軟件包已經包括在默認的 CentOS-Extras 軟件源里。因此想要安裝 docker,只需要運行下面的 yum 命令:

  1. [root@localhost ~]# yum install docker

啟動 Docker 服務

安裝完成后,使用下面的命令來啟動 docker 服務,並將其設置為開機啟動:

  1. [root@localhost ~]# service docker start
  2. [root@localhost ~]# chkconfig docker on

(LCTT 譯注:此處采用了舊式的 sysv 語法,如采用CentOS 7中支持的新式 systemd 語法,如下:

  1. [root@localhost ~]# systemctl start docker.service
  2. [root@localhost ~]# systemctl enable docker.service

下載官方的 CentOS 鏡像到本地 (LCTT 譯注:由於 Docker 被 :-< ,所以請使用 http://docker.cn  的鏡像,感謝 @馬全一 的鏡像。 )

  1. [root@localhost ~]# docker pull centos
  2. Pulling repository centos
  3. 192178b11d36:Download complete 
  4. 70441cac1ed5:Download complete 
  5. ae0c2d0bdc10:Download complete 
  6. 511136ea3c5a:Download complete 
  7. 5b12ef8fd570:Download complete

確認 CentOS 鏡像已經被獲取:

  1. [root@localhost ~]# docker images centos
  2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  3. centos centos5 192178b11d362 weeks ago 466.9 MB
  4. centos centos6 70441cac1ed52 weeks ago 215.8 MB
  5. centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
  6. centos latest ae0c2d0bdc10 2 weeks ago 224 MB

運行一個 Docker 容器:

  1. [root@localhost ~]# docker run --t centos /bin/bash
  2. [root@dbf66395436d /]#

我們可以看到,CentOS 容器已經被啟動,並且我們得到了 bash 提示符。在 docker 命令中我們使用了 “-i 捕獲標准輸入輸出”和 “-t 分配一個終端或控制台”選項。若要斷開與容器的連接,輸入 exit。

  1. [root@cd05639b3f5c /]# cat /etc/RedHat-release 
  2. CentOSLinux release 7.0.1406(Core)
  3. [root@cd05639b3f5c /]#exit
  4. exit
  5. [root@localhost ~]#

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

  1. [root@localhost ~]# docker search ubuntu
  2. [root@localhost ~]# docker search fedora

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

 

 

轉載:http://www.linuxidc.com/Linux/2014-12/110034.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM