鏡像下載、域名解析、時間同步請點擊 阿里巴巴開源鏡像站
在新主機上首次安裝Docker Engine之前,需要設(shè)置Docker存儲庫。之后,您可以從存儲庫安裝和更新Docker。
設(shè)置存儲庫
安裝yum-utils軟件包(提供yum-config-manager 實用程序)并設(shè)置穩(wěn)定的存儲庫。
[root@localhost ~]# yum install -y yum-utils
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.lzu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解決依賴關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 yum-utils.noarch.0.1.1.31-24.el7 將被 升級
---> 軟件包 yum-utils.noarch.0.1.1.31-52.el7 將被 更新
--> 正在處理依賴關(guān)系 yum >= 3.4.3-143,它被軟件包 yum-utils-1.1.31-52.el7.noarch 需要
--> 正在檢查事務(wù)
---> 軟件包 yum.noarch.0.3.4.3-118.el7.centos 將被 升級
---> 軟件包 yum.noarch.0.3.4.3-163.el7.centos 將被 更新
--> 正在處理依賴關(guān)系 rpm >= 4.11.3-22,它被軟件包 yum-3.4.3-163.el7.centos.noarch 需要
--> 正在處理依賴關(guān)系 python-urlgrabber >= 3.10-8,它被軟件包 yum-3.4.3-163.el7.centos.noarch 需要
--> 正在檢查事務(wù)
---> 軟件包 python-urlgrabber.noarch.0.3.10-4.el7 將被 升級
---> 軟件包 python-urlgrabber.noarch.0.3.10-9.el7 將被 更新
---> 軟件包 rpm.x86_64.0.4.11.1-16.el7 將被 升級
--> 正在處理依賴關(guān)系 rpm = 4.11.1-16.el7,它被軟件包 rpm-python-4.11.1-16.el7.x86_64 需要
--> 正在處理依賴關(guān)系 rpm = 4.11.1-16.el7,它被軟件包 rpm-libs-4.11.1-16.el7.x86_64 需要
---> 軟件包 rpm.x86_64.0.4.11.3-40.el7 將被 更新
--> 正在檢查事務(wù)
---> 軟件包 rpm-libs.x86_64.0.4.11.1-16.el7 將被 升級
--> 正在處理依賴關(guān)系 rpm-libs(x86-64) = 4.11.1-16.el7,它被軟件包 rpm-build-libs-4.11.1-16.el7.x86_64 需要
---> 軟件包 rpm-libs.x86_64.0.4.11.3-40.el7 將被 更新
---> 軟件包 rpm-python.x86_64.0.4.11.1-16.el7 將被 升級
---> 軟件包 rpm-python.x86_64.0.4.11.3-40.el7 將被 更新
--> 正在檢查事務(wù)
---> 軟件包 rpm-build-libs.x86_64.0.4.11.1-16.el7 將被 升級
---> 軟件包 rpm-build-libs.x86_64.0.4.11.3-40.el7 將被 更新
--> 解決依賴關(guān)系完成
依賴關(guān)系解決
============================================================================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
============================================================================================================================================================================================================================
正在更新:
yum-utils noarch 1.1.31-52.el7 base 121 k
為依賴而更新:
python-urlgrabber noarch 3.10-9.el7 base 108 k
rpm x86_64 4.11.3-40.el7 base 1.2 M
rpm-build-libs x86_64 4.11.3-40.el7 base 107 k
rpm-libs x86_64 4.11.3-40.el7 base 278 k
rpm-python x86_64 4.11.3-40.el7 base 83 k
yum noarch 3.4.3-163.el7.centos base 1.2 M
事務(wù)概要
============================================================================================================================================================================================================================
升級 1 軟件包 (+6 依賴軟件包)
總計:3.1 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : rpm-libs-4.11.3-40.el7.x86_64 1/14
正在更新 : rpm-4.11.3-40.el7.x86_64 2/14
正在更新 : rpm-build-libs-4.11.3-40.el7.x86_64 3/14
正在更新 : rpm-python-4.11.3-40.el7.x86_64 4/14
正在更新 : python-urlgrabber-3.10-9.el7.noarch 5/14
正在更新 : yum-3.4.3-163.el7.centos.noarch 6/14
正在更新 : yum-utils-1.1.31-52.el7.noarch 7/14
清理 : yum-utils-1.1.31-24.el7.noarch 8/14
清理 : yum-3.4.3-118.el7.centos.noarch 9/14
清理 : rpm-python-4.11.1-16.el7.x86_64 10/14
清理 : python-urlgrabber-3.10-4.el7.noarch 11/14
清理 : rpm-build-libs-4.11.1-16.el7.x86_64 12/14
清理 : rpm-libs-4.11.1-16.el7.x86_64 13/14
清理 : rpm-4.11.1-16.el7.x86_64 14/14
驗證中 : python-urlgrabber-3.10-9.el7.noarch 1/14
驗證中 : rpm-python-4.11.3-40.el7.x86_64 2/14
驗證中 : yum-utils-1.1.31-52.el7.noarch 3/14
驗證中 : rpm-4.11.3-40.el7.x86_64 4/14
驗證中 : yum-3.4.3-163.el7.centos.noarch 5/14
驗證中 : rpm-libs-4.11.3-40.el7.x86_64 6/14
驗證中 : rpm-build-libs-4.11.3-40.el7.x86_64 7/14
驗證中 : python-urlgrabber-3.10-4.el7.noarch 8/14
驗證中 : rpm-python-4.11.1-16.el7.x86_64 9/14
驗證中 : rpm-build-libs-4.11.1-16.el7.x86_64 10/14
驗證中 : rpm-libs-4.11.1-16.el7.x86_64 11/14
驗證中 : yum-utils-1.1.31-24.el7.noarch 12/14
驗證中 : yum-3.4.3-118.el7.centos.noarch 13/14
驗證中 : rpm-4.11.1-16.el7.x86_64 14/14
更新完畢:
yum-utils.noarch 0:1.1.31-52.el7
作為依賴被升級:
python-urlgrabber.noarch 0:3.10-9.el7 rpm.x86_64 0:4.11.3-40.el7 rpm-build-libs.x86_64 0:4.11.3-40.el7 rpm-libs.x86_64 0:4.11.3-40.el7 rpm-python.x86_64 0:4.11.3-40.el7 yum.noarch 0:3.4.3-163.el7.centos
完畢!
添加下載地址:
yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
安裝DOCKER引擎
安裝最新版本的Docker Engine和容器,或轉(zhuǎn)到下一步以安裝特定版本: 過程比較漫長 等等就好
yum install docker-ce docker-ce-cli containerd.io
如果提示您接受GPG密鑰,請驗證指紋是否匹配 ??060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35??,如果是,則接受它。
不出意外 你會看到 成功兩個字 ,
啟動Docker。 systemctl start docker
別急 如果啟動失敗了 說明 版本問題導(dǎo)致的
你可以先卸載 再 繼續(xù)安裝 ,當然是選擇性安裝 根據(jù)版本號安裝
要安裝特定版本的Docker Engine,請在存儲庫中列出可用版本,然后選擇并安裝:
一個。列出并排序您存儲庫中可用的版本。此示例按版本號(從高到低)對結(jié)果進行排序,
[root@localhost lib]# yum list docker-ce --showduplicates | sort -r
已加載插件:fastestmirror, langpacks
可安裝的軟件包
* updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
* extras: mirrors.aliyun.com
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
返回的列表取決于啟用了哪些存儲庫,并且特定于您的CentOS版本(.el7在本示例中以后綴表示)。
b。通過其完全合格的軟件包名稱安裝特定版本,該軟件包名稱是軟件包名稱(docker-ce)加上版本字符串(第二列),從第一個冒號(:)一直到第一個連字符,并用連字符(-)分隔。例如,docker-ce-18.09.1。
yum install docker-ce- docker-ce-cli- containerd.io
首先卸載之前的安裝 (當然你也可以選擇升級linux內(nèi)核)
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
執(zhí)行完成后繼續(xù)下面的執(zhí)行
自定義安裝
[root@localhost ~]# yum install docker-ce-17.09.1.ce
BDB2053 Freeing read locks for locker 0x72a: 51685/139945979692864
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.lzu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解決依賴關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 docker-ce.x86_64.0.17.09.1.ce-1.el7.centos 將被 安裝
--> 解決依賴關(guān)系完成
依賴關(guān)系解決
=============================================================================================================================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
=============================================================================================================================================================================================================================================================================
正在安裝:
docker-ce x86_64 17.09.1.ce-1.el7.centos docker-ce-stable 21 M
事務(wù)概要
=============================================================================================================================================================================================================================================================================
安裝 1 軟件包
總下載量:21 M
安裝大小:21 M
Is this ok [y/d/N]: y
Downloading packages:
docker-ce-17.09.1.ce-1.el7.cen FAILED 91% [==================================================================================================== ] 1.2 B/s | 19 MB 433:07:05 ETA
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.1.ce-1.el7.centos.x86_64.rpm: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.1.ce-1.el7.centos.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
docker-ce-17.09.1.ce-1.el7.centos.x86_64.rpm | 21 MB 00:00:56
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : docker-ce-17.09.1.ce-1.el7.centos.x86_64 1/1
驗證中 : docker-ce-17.09.1.ce-1.el7.centos.x86_64 1/1
已安裝:
docker-ce.x86_64 0:17.09.1.ce-1.el7.centos
完畢!
[root@localhost ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: start-limit) since 二 2020-04-07 21:52:23 CST; 41min ago
Docs: https://docs.docker.com
Main PID: 51154 (code=exited, status=1/FAILURE)
4月 07 21:52:21 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
4月 07 21:52:21 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
4月 07 21:52:21 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
4月 07 21:52:21 localhost.localdomain systemd[1]: docker.service failed.
4月 07 21:52:23 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart.
4月 07 21:52:23 localhost.localdomain systemd[1]: Stopped Docker Application Container Engine.
4月 07 21:52:23 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service
4月 07 21:52:23 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
4月 07 21:52:23 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
4月 07 21:52:23 localhost.localdomain systemd[1]: docker.service failed.
[root@localhost ~]# systemctl start docker.service
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2020-04-07 22:33:51 CST; 8s ago
Docs: https://docs.docker.com
Main PID: 53799 (dockerd)
Memory: 14.7M
CGroup: /system.slice/docker.service
├─53799 /usr/bin/dockerd
└─53805 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.384733771+08:00" level=info msg="devmapper: Successfully created filesystem xfs on device docker-253:1-2180700-base"
4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.460507062+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.460884311+08:00" level=warning msg="mountpoint for pids not found"
4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.461183759+08:00" level=info msg="Loading containers: start."
4月 07 22:33:50 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:50.901283597+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.123313352+08:00" level=info msg="Loading containers: done."
4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.140985188+08:00" level=info msg="Docker daemon" commit=19e2cf6 graphdriver(s)=devicemapper version=17.09.1-ce
4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.141114485+08:00" level=info msg="Daemon has completed initialization"
4月 07 22:33:51 localhost.localdomain dockerd[53799]: time="2020-04-07T22:33:51.164127752+08:00" level=info msg="API listen on /var/run/docker.sock"
4月 07 22:33:51 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
然后運行示例程序 在這之前 需要引入國內(nèi)的鏡像地址 當然你有翻墻 可以不要的
通過運行??hello-world?? 映像來驗證是否正確安裝了Docker Engine 。
docker run hello-world
配置
/etc/docker 目錄下創(chuàng)建 daemon.json
[root@localhost docker]# ll
總用量 8
-rw-r--r-- 1 root root 65 4月 7 22:50 daemon.json
-rw------- 1 root root 244 4月 7 22:33 key.json
然后里面的內(nèi)容為
{ "registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] }
保存后 執(zhí)行 測試命令
[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:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@localhost docker]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@localhost docker]#
?
本文轉(zhuǎn)自: https://blog.51cto.com/u_15446828/4775102
審核編輯:符乾江
評論
查看更多