如何在 CentOS 7 上安裝 Docker
Docker 是一個開源專案,它自動化了在軟體容器內部署應用程式的過程。容器允許開發者打包所有專案資源,例如庫、依賴項、資產等。Docker 使用 **Go 語言**編寫,由 **Dotcloud** 開發。它基本上是一個容器引擎,它使用 Linux 核心特性(如名稱空間和控制組)在作業系統之上建立容器,並自動化容器上的應用程式部署。
安裝 Docker
在 CentOS 上安裝 Docker 之前,需要更新 CentOS 包。要更新包,請使用以下命令:
# yum -y update
示例輸出應如下所示:
Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * elrepo: mirrors.ircam.fr * epel: mirror01.idc.hinet.net * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in Resolving Dependencies --> Running transaction check ---> Package autocorr-en.noarch 1:4.3.7.2-5.el7 will be updated ---> Package autocorr-en.noarch 1:4.3.7.2-5.el7_2.1 will be an update ---> Package avahi.x86_64 0:0.6.31-15.el7 will be updated ---> Package avahi.x86_64 0:0.6.31-15.el7_2.1 will be an update ---> Package avahi-autoipd.x86_64 0:0.6.31-15.el7 will be updated ---> Package avahi-autoipd.x86_64 0:0.6.31-15.el7_2.1 will be an update ............
要安裝 Docker,請使用以下命令:
# yum -y install docker docker-registry
示例輸出應如下所示:
Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * elrepo: mirrors.ircam.fr * epel: epel.mirror.net.in * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in Resolving Dependencies --> Running transaction check ---> Package docker.x86_64 0:1.8.2-10.el7.centos will be installed --> Processing Dependency: docker-selinux >= 1.8.2-10.el7.centos for package: docker-1.8.2-10.el7.centos.x86_64 ---> Package docker-registry.x86_64 0:0.9.1-7.el7 will be installed --> Processing Dependency: python-sqlalchemy >= 0.9.8-1 for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-backports-lzma >= 0.0.2-8 for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-requests for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-gunicorn for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-gevent for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-flask for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-blinker for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: m2crypto for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: PyYAML for package: docker-registry-0.9.1-7.el7.x86_64 .......
啟動 Docker
要在啟動時啟動 Docker,請使用以下命令:
# systemctl enable docker.service
示例輸出應如下所示:
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
要啟動 Docker,請使用以下命令:
# systemctl start docker.service
要查詢 Docker 的狀態,請使用以下命令:
# systemctl status docker.service
示例輸出應如下所示:
docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2016-02-29 16:01:24 IST; 1min 18s ago Docs: https://dockerdocs.tw Main PID: 27398 (docker) CGroup: /system.slice/docker.service └─27398 /usr/bin/docker daemon --selinux-enabled Feb 29 16:00:56 linux docker[27398]: time="2016-02-29T16:00:56.139817103+05...e" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.314033208+05...e" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.314422184+05...e" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.401448064+05...1" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.647321427+05...e" Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.713353670+05...." Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716886255+05...." Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716900165+05...n" Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716913621+05...os Feb 29 16:01:24 linux systemd[1]: Started Docker Application Container Engine. Hint: Some lines were ellipsized, use -l to show in full. .........
下載 CentOS 的 Docker 容器
要下載 Docker 容器,請使用以下命令:
# docker pull centos
示例輸出應如下所示:
Using default tag: latest Trying to pull repository docker.io/library/centos ... latest: Pulling from library/centos 47d44cb6f252: Pull complete f5079557f135: Pull complete 42c2aa730369: Pull complete 0e0217391d41: Pull complete library/centos:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Digest: sha256:1272ae53bac7bf054dd209a0b4a8629bcc39526c2a767427c7639b630a224a9e Status: Downloaded newer image for docker.io/centos:latest .................
執行 Docker 容器
要執行 Docker,需要一個帶有 **bash shell** 的基本 **CentOS** 容器。要執行 Docker,請使用以下命令:
# docker run -i -t centos /bin/bash
以上命令將使用者帶入 CentOS Docker 容器內的 **bash shell**。要退出 Docker,請使用 **Ctrl+p** 或 **Ctrl+q** 快捷鍵。有很多社群已經包含在 Docker 容器中,可以透過搜尋找到。
例如,要搜尋 **CentOS** 社群,請使用以下命令:
# docker search centos
示例輸出應如下所示:
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/centos The official build of CentOS. 1965 [OK] docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8... 15 [OK] docker.io docker.io/million12/centos-supervisor Base CentOS-7 with supervisord launcher, h... 9 [OK] docker.io docker.io/blalor/centos Bare-bones base CentOS 6.5 image 8 [OK] docker.io docker.io/nimmis/java-centos This is docker images of CentOS 7 with dif... 7 [OK] docker.io docker.io/torusware/speedus-centos Always updated official CentOS docker imag... 7 [OK] docker.io docker.io/centos/mariadb55-centos7 3 [OK] docker.io docker.io/nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... 3 [OK] docker.io docker.io/nickistre/centos-lamp LAMP on centos setup 3 [OK] docker.io docker.io/consol/sakuli-centos-xfce Sakuli end-2-end testing and monitoring co... 2 [OK] docker.io docker.io/darksheer/centos Base Centos Image -- Updated hourly 1 [OK] docker.io docker.io/layerworx/centos CentOS container with etcd, etcdctl, confd... 1 [OK] docker.io docker.io/lighthopper/orientdb-centos A Dockerfile for creating an OrientDB imag... 1 [OK] docker.io docker.io/softvisio/centos Centos 1 [OK] docker.io docker.io/yajo/centos-epel CentOS with EPEL and fully updated 1 [OK] docker.io docker.io/blacklabelops/centos CentOS Base Image! Built and Updates Daily! 0 [OK] docker.io docker.io/dmglab/centos CentOS with some extras - This is for the ... 0 [OK] docker.io docker.io/ericuni/centos centos dev 0 [OK] docker.io docker.io/grayzone/centos auto build for centos. 0 [OK] docker.io docker.io/insaneworks/centos CentOS 6.5 x86_64 + @update 0 [OK] docker.io docker.io/januswel/centos yum update-ed CentOS image 0 [OK] docker.io docker.io/jsmigel/centos-epel Docker base image of CentOS w/ EPEL installed 0 [OK] docker.io docker.io/lighthopper/openjdk-centos A Dockerfile for creating an OpenJDK image... 0 [OK] docker.io docker.io/timhughes/centos Centos with systemd installed and running 0 [OK] docker.io docker.io/ustclug/centos USTC centos 0 [OK]
恭喜!現在您已經知道“如何在 CentOS 7 上安裝 Docker”。我們將在下一篇文章中學習更多關於這類 Linux 命令的內容。繼續關注!
廣告
資料結構
網路
關係型資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP