Centos 7.2 下安裝Docker CE

準備

環(huán)境:CentOS Linux release 7.2.1511 (Core)
參考頁面:Docker 官方安裝指引
安裝Docker CE前,請先準備好一臺CentOS 服務(wù)器,如果你是在Windows下進行測試,推薦使用VirtualBox創(chuàng)建虛擬機。

Virtual Box VM

通過yum Docker 源倉庫安裝Docker CE

官方的安裝指引里提到了三種方式:
①:通過yum Docker源倉庫安裝
②:通過下載的安裝包安裝
③:通過快捷腳本安裝

本文將通過yum Docker源倉庫的方式來安裝Docker CE

第一步、安裝yum 管理依賴包

sudo yum install-y yum-utils device-mapper-persistent-data lvm2

如果你的系統(tǒng)已經(jīng)安裝了yum管理工具,則會看到如下的提示:

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package yum-utils-1.1.31-34.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.5.5-1.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.130-5.el7.x86_64 already installed and latest version
Nothing to do

第二步、添加Docker 源倉庫

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

你將看到如下的提示:

Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
docker-ce.repo? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 2.4 kB? 00:00:00? ?
repo saved to /etc/yum.repos.d/docker-ce.repo

第三步、安裝Docker CE

sudo yum install docker-ce docker-ce-cli containerd.io

如果不出意外,Docker?將順利安裝完成。但也有可能遇到以下的錯誤:

[root@localhost docker]# sudo yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.2-3.el7 will be installed
---> Package docker-ce.x86_64 3:18.09.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: libseccomp.so.2()(64bit) for package: 3:docker-ce-18.09.1-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:18.09.1-3.el7 will be installed
--> Processing Dependency: libltdl.so.7()(64bit) for package: 1:docker-ce-cli-18.09.1-3.el7.x86_64
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: 3:docker-ce-18.09.1-3.el7.x86_64
---> Package libcgroup.x86_64 0:0.41-8.el7 will be installed
---> Package libseccomp.x86_64 0:2.2.1-1.el7 will be installed
---> Package libtool-ltdl.x86_64 0:2.4.2-20.el7 will be installed
--> Finished Dependency Resolution
Error: Package: 3:docker-ce-18.09.1-3.el7.x86_64 (docker-ce-stable)
? ? ? ? ? ?Requires: container-selinux >= 2.9
Error: Package: 3:docker-ce-18.09.1-3.el7.x86_64 (docker-ce-stable)
? ? ? ? ? ?Requires: libseccomp >= 2.3
? ? ? ? ? ?Available: libseccomp-2.2.1-1.el7.i686 (CENTOS7.2-basic)
? ? ? ? ? ? ? ?libseccomp = 2.2.1-1.el7
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest

這里我們遇到了一個錯誤,安裝Docker CE?需要依賴?container-selinux >= 2.9,我們只需要安裝一下這個依賴包即可。

安裝container-selinux 2.9

[root@localhost docker]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost docker]# yum install epel-release
[root@localhost docker]# yum install?container-selinux?

因為安裝container-selinux?需要依賴epel源,所以這里需要先安裝epel源,這里我們使用了阿里云的源倉庫。
安裝完container-selinux?后,再一次執(zhí)行上面的docker?安裝指令,就可以順利安裝完成了。

第四步、啟動Docker?服務(wù)

[root@localhost docker]# systemctl enable docker? ? //?設(shè)置開機啟動
[root@localhost docker]# systemctl start docker? ? ? ? //?啟動docker
[root@localhost docker]#?systemctl status docker?

你將看到Docker的狀態(tài)信息如下:狀態(tài)為running,表示docker?已經(jīng)運行了。

● docker.service - Docker Application Container Engine
? ?Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
? ?Active: active (running) since Thu 2019-01-31 14:58:31 CST; 6h ago
? ? ?Docs: https://docs.docker.com
Main PID: 80152 (dockerd)
? ?Memory: 38.5M
? ?CGroup: /system.slice/docker.service
? ? ? ? ? ?└─80152 /usr/bin/dockerd -H fd://

[root@localhost docker]# docker info? ? ? ? ?//查看一下docker?的信息

你將看到如下信息:

Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.1
Storage Driver: devicemapperPool Name: docker-253:3-16854418-pool
Pool Blocksize: 65.54kB
。。。。。。。。。。。。。。。。。。。。。。。。

第五步、運行第一個Docker應(yīng)用

Docker?也和其他的編程語言一樣,也提供了非常著名的Hello World應(yīng)用。我們只需要執(zhí)行如下指令即可運行第一個Docker?應(yīng)用:

[root@localhost docker]# docker run?hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.

因為是第一次運行hello-world,所以本地沒有這個鏡像,因此會自動從遠程的docker倉庫下載該鏡像。然后顯示出:Hello from Docker!

執(zhí)行:docker ps,將會顯示出剛剛已經(jīng)運行的容器
執(zhí)行:docker images,將會顯示已經(jīng)下載的hello-world鏡像

到此,我們的Docker?基本上就已經(jīng)安裝完成了,開始你的Docker之旅吧。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容