1. 程式人生 > >Linux安裝Docker CE

Linux安裝Docker CE

# yum -y install yum-utils device-mapper-persistent-data lvm2
Installed:
  yum-utils.noarch 0:1.1.31-42.el7                                                                

Dependency Installed:
  libxml2-python.x86_64 0:2.9.1-6.el7_2.3          python-chardet.noarch 0:2.2.1-1.el7_1         
  python-kitchen.noarch
0:1.1.1-5.el7 Complete!

使用以下命令來設定穩定的儲存庫。

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
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-c e.reporepo saved to /etc/yum.repos.d/docker-ce.repo

(本人沒有使用)可選:啟用邊緣和測試儲存庫。這些儲存庫包含在docker.repo上面的檔案中,但預設情況下是禁用的。可以將它們與穩定的儲存庫一起啟用

# yum-config-manager --enable docker-ce-edge
# yum-config-manager --enable docker-ce-test

以下命令禁用邊緣儲存庫。注意:從Docker 17.06開始,穩定版本也被推到邊緣並測試版本庫

# yum-config-manager --disable--enable
# yum-config-manager --disable docker-ce-edge

安裝DOCKER CE 17.12.0.ce-1.el7.centos

# yum -y install docker-ce
Installed:
  docker-ce.x86_64 0:17.12.0.ce-1.el7.centos                                                                            

Dependency Installed:
  audit-libs-python.x86_64 0:2.7.6-3.el7                           checkpolicy.x86_64 0:2.5-4.el7                       
  container-selinux.noarch 2:2.36-1.gitff95335.el7                 libcgroup.x86_64 0:0.41-13.el7                       
  libseccomp.x86_64 0:2.3.1-3.el7                                  libsemanage-python.x86_64 0:2.5-8.el7                
  policycoreutils-python.x86_64 0:2.5-17.1.el7                     python-IPy.noarch 0:0.75-6.el7                       
  setools-libs.x86_64 0:3.3.8-1.1.el7                             

Complete!

版本並不是越高越好的,那麼如何安裝指定版本DOCKER CE 呢

# yum list docker-ce --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
 * epel: mirrors.ustc.edu.cn
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.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
Available Packages

該命令列出可用的版本。按版本號對結果進行排序,從最高到最低並被截斷。列表的內容取決於啟用了哪些儲存庫,並且特定於您的CentOS .el7版本(在此示例中,由版本的字尾指示)。選擇一個特定的版本進行安裝。第二列是版本字串。您可以使用整個版本字串,但您至少需要包含第一個連字元。第三列是儲存庫名稱,它指示軟體包來自哪個儲存庫並且通過擴充套件其穩定性級別。
要安裝特定版本,請將版本字串附加到包名稱並用連字元(-)分隔。即:

# yum install <FULLY-QUALIFIED-PACKAGE-NAME>

如,若安裝17.09.1版本,則命令為

# yum install docker-ce-17.09.1.ce-1.el7.centos

啟動docker

# systemctl start docker

通過執行hello-world 映像驗證安裝是否正確

# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

升級DOCKER CE
要升級Docker CE,請下載較新的軟體包檔案並重復 安裝過程,yum -y upgrade 而不是使用yum -y install,然後指向新檔案。
解除安裝Docker CE

# yum -y remove docker-ce

該命令不會自動刪除主機上的影象,容器,卷或自定義配置檔案。刪除所有影象,容器和卷:

# rm -rf /var/lib/docker

還必須手動刪除任何已編輯的配置檔案

docker安裝後步驟(作為非root使用者管理Docker)
建立docker組

$ sudo groupadd docker

將使用者新增到docker組中

$ sudo usermod -aG docker $USER

登出並重新登入(如果在虛擬機器上進行測試,則可能需要重新啟動虛擬機器才能使更改生效)
驗證可以不使用命令sudo執行docker

$ docker run hello-world

如果最初sudo在將使用者新增到docker組之前執行Docker CLI命令,則可能會看到以下錯誤,這表明~/.docker/目錄是由於sudo命令使用不正確的許可權建立的。

WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied

要解決此問題,需要刪除~/.docker/目錄(它會自動重新建立,但任何自定義設定都會丟失),或使用以下命令更改其所有權和許可權:

$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx "/home/$USER/.docker" -R

配置開機啟動

# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

禁止開機啟動

# systemctl disable docker

Docker會自動配置為在啟動時使用 upstart。要禁用此行為,請使用以下命令:

# echo manual | tee /etc/init.d/docker.override
# systemctl enable docker.service

配置Docker守護程式偵聽連線的位置
預設情況下,Docker守護程式在UNIX套接字上偵聽連線。要使Docker能夠接受來自遠端主機的請求,可以將其配置為監聽IP地址和埠。它仍然需要在UNIX套接字上偵聽,以接受來自本地客戶端的請求。
將hosts陣列設定/etc/docker/daemon.json為連線到UNIX套接字和IP地址,如下所示:
CentOS 6的配置方式

# cat /etc/docker/daemon.json 
{
"hosts": ["fd://", "tcp://0.0.0.0:2375"]
}

CentOS 7之後的配置方式

# cat /usr/lib/systemd/system/docker.service
12 ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

firewall開啟相應埠

# firewall-cmd --permanent --add-port=2375/tcp
success
# systemctl restart firewalld
# iptables -L -n    //驗證檢視

重新載入systemctl配置

# systemctl daemon-reload

重啟docker

# systemctl restart docker.service

再次檢查該dockerd命令現在是否偵聽檔案描述符和網路地址

#  ps aux |grep dockerd
root       2352  0.4  1.3 446348 26752 ?        Ssl  13:23   0:00 /usr/bin/dockerd
root       2357  0.5  1.1 300860 23864 ?        Ssl  13:23   0:00 docker-containerd --config /var/run/docker/containerd/
containerd.tomlroot       2477  0.0  0.0 112660   976 pts/1    S+   13:25   0:00 grep --color=auto docker

如果沒有發現對應的程序,則嘗試reboot機器解決
否則再檢查override.conf,修改為如下樣式,然後重新載入systemctl配置,啟動docker

# cat /etc/systemd/system/docker.service.d/override.conf 
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
#ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

為docker指定DNS伺服器(解析網路內部的主機)
建立或編輯預設為daemon.json檔案的docker守護程式配置檔案,該檔案控制docker守護程式配置

# cat /etc/docker/daemon.json 
{
    "dns": ["8.8.8.8", "8.8.4.4"]
}

如果內部DNS伺服器無法解析公共IP地址,至少要包含一個DNS伺服器,以便可以連線到Docker Hub,以便容器可以解析網際網路域名。
重啟docker

# systemctl restart docker

驗證Docker可以通過嘗試拉取影象來解析外部IP地址

# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
Status: Image is up to date for hello-world:latest

驗證Docker容器可以通過對其進行ping來解析內部主機名

# docker run --rm -it alpine ping -c4 <my_internal_host>
# docker run --rm -it alpine ping -c4 10.226.38.82
PING 10.226.38.82 (10.226.38.82): 56 data bytes
64 bytes from 10.226.38.82: seq=0 ttl=127 time=2.139 ms
64 bytes from 10.226.38.82: seq=1 ttl=127 time=0.705 ms
64 bytes from 10.226.38.82: seq=2 ttl=127 time=0.718 ms
64 bytes from 10.226.38.82: seq=3 ttl=127 time=0.663 ms

--- 10.226.38.82 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.663/1.056/2.139 ms

配置Docker守護程序
守護程序包含許多配置選項,可以在手動啟動Docker時將其作為標誌傳遞,或者在daemon.json配置檔案中進行設定。推薦使用第二種方法,因為重新啟動Docker時,這些配置更改仍然存在。(附:dockerd獲取配置選項的完整列表
將啟動選項放入daemon.json檔案並重新啟動Docker

# cat /etc/docker/daemon.json 
{
    "debug": true,
    "hosts": ["tcp://0.0.0.0:2375"],
    "dns": ["8.8.8.8", "8.8.4.4"]
}
# systemctl daemon-reload
# systemctl restart docker

如果在daemon.json中指定 hosts條目,可能會導致配置衝突,並且Docker無法啟動。要解決此問題,新建檔案

# touch /etc/systemd/system/docker.service.d/docker.conf

使用以下內容,以刪除在-H預設情況下啟動守護程式時使用的引數。

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd

檢查Docker是否正在執行,可使用以下命令,可知,docker正常執行

# systemctl status docker
# ps aux|grep docker
# lsof -i:2375
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dockerd 17665 root    5u  IPv6  94150      0t0  TCP *:2375 (LISTEN)

報錯解決,如下:

# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
# docker info
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

以上均報同一個錯誤,但通過ps命令查詢docker程序為正常,解決方法如下:

# cat /etc/systemd/system/docker.service.d/docker.conf 

docker.conf,新增DOCKER_OPTS行

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd
DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"

~/.bashrc 檔案,新增export DOCKER_HOST行

# cat ~/.bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
export DOCKER_HOST=tcp://localhost:2375

然後重新載入

# source ~/.bashrc

驗證

# echo $DOCKER_HOST
tcp://localhost:2375

重啟docker進行驗證

# systemctl restart docker
# docker info
Containers: 4
 Running: 0
 Paused: 0
 Stopped: 4
Images: 2
Server Version: 17.12.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-693.11.6.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.937GiB
Name: blPqoh139504
ID: WYU4:WESS:P4FR:UTOB:W5OO:NSYZ:DZ55:PGA4:37CA:TXRO:RPHU:TC2L
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 19
 Goroutines: 32
 System Time: 2018-02-13T15:52:10.442599614+08:00
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

可見最後出現的2個WARNING,可解決可不解決。若解決,方法為在sysctl.conf檔案最末新增如下內容:

# cat /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1

重新載入sysctl即可

# sysctl -p

相關推薦

Linux安裝Docker-CE

安裝環境介紹 作業系統:CentOS7 Docker版本:Docker-CE最新版本 安裝Docker-CE 官方連結:https://docs.docker.com/engine/installation/ 解除安裝舊版本docker:

Linux安裝Docker CE

# yum -y install yum-utils device-mapper-persistent-data lvm2 Installed: yum-utils.noarch 0:1.1.31-42.el7

Linux CentOS7 Docker-CE 安裝

雖然安裝在docker官網是有的,但是,大部分的內容都是安裝時不需要的。 安裝所需的 # yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 # yum-config-manager \

linux CentOS7 64位系統 安裝docker-ce

1. docker 概述 目前,docker有2個版本: 1. Community Edition (CE) -- docker-ce  docker的社群版本非常適合希望開始使用Docker並嘗試基於容器的應用程式的個人開發人員和小型團隊。 2. Enterpr

Linux安裝Docker CE (以CentOS 7為例)

 系統要求:centos 7 64位,centos-extras儲存庫必須啟用。 解除安裝舊版Docker 查詢當前的Docker版本 $ docker -v            如果存在已安

linux實戰--(6)--CentOS7安裝Docker CE

目錄 一、快速安裝 二、標準安裝 Docker CE 1、系統要求 2、解除安裝舊版本Docker 3、安裝 3.1、倉庫安裝(推薦) 3.2、RPM安裝 3.3、指令碼安裝

centos7 安裝docker-ce ,最新版本docker

move tar fast inf systemctl ont tty epo 可用 直接用yum install docker -y安裝的docker版本為1.12,但是docker發展很快,現在都17.06.2了。docker-ce是指docker的社區版 卸載老版本的

CentOS 安裝 Docker CE

app wiki 軟件 systemctl 並且 get use 準備 腳本安裝 準備工作 系統要求 Docker CE 支持 64 位版本 CentOS 7,並且要求內核版本不低於 3.10。 CentOS 7 滿足最低內核的要求,但由於內核版本比較低,部分功能(如 ov

Windows 10 PC 安裝 Docker CE

load exe hyper 網絡問題 nload 建議 git -c search 系統要求 Docker CE 支持 64 位版本的 Windows 10 Pro,且必須開啟 Hyper-V。 安裝 點擊以下鏈接下載 stable 或 edge 版本的 Docker C

CentOS7安裝Docker CE

匹配 界面 centos disable 授權 mon graphic init logs 好久沒有打開CentOS虛擬機了,昨天晚上一打開,圖形界面就停留在了許可證信息未授權的問題,點擊以後界面沒有什麽反應。所以就直接關了,查了一天的資料 解決方案如下: 1、界面停留

centos7 安裝docker-ce ,最新版本dockerdocker阿裏雲加速

load sso all ttr bind tar make avr start 直接用yum install docker -y安裝的docker版本為1.12,但是docker發展很快,現在都17.06.2了。docker-ce是指docker的社區版 卸載老版本的 d

安裝Docker CE(社區版本)

新版本 其他 -c 非root 系統 ins 端口 data- per OS要求 需要64位版本的CentOS 7 centos-extra庫必須啟用。默認情況下啟用此庫,但如果已禁用該存儲庫,則需要重新啟用該存儲庫 卸載舊版本 較老版本的Docker被稱為doc

ubuntu安裝docker-ce

版本 erro nbsp 依賴 triggers 更新 一個 package ron Docker Community Edition (CE)/Docker社區版非常適合希望開始使用Docker並嘗試使用基於容器的應用程序的開發人員和小型團隊。Docker CE有2個版本

centos7安裝docker-ce新版

common .com sel nload utils 安裝 centos7安裝 root ger 參考官網地址 官方網站:https://docs.docker.com/engine/installation/linux/docker-ce/centos/ 先卸載系統的舊

ubuntu14安裝docker-ce

tor gpg inux library transport produces 最新版 led rec 先卸載舊的docker sudo apt-get remove docker docker-engine docker.io docker-ce 通過HTTPS使用存儲庫

Centos7 安裝docker ce

his sys -s flow put res spa som daemon 一. 安裝docker 1.升級rpm包 yum -y update 2. 通過命令設置Docker CE 資源庫: yum install -y yum-utils

ubuntu14.04/16.04安裝docker-ce-17.03.1

ftw ubunt deb repos ans http sudo .com star sudo apt-get updatesudo apt-get -y install apt-transport-https ca-certificates curl software-

Linux 安裝Docker Linux 虛擬鏡像下載

.com div blank docke docker 安裝docker wget 5.1 star Linux虛擬鏡像下載: http://mirrors.163.com/centos/7.5.1804/isos/x86_64/ Docker 安裝 wget -qO-

Centos7 安裝 Docker CE

ast systemctl eof mkdir -c mon ref epo lin 安裝 先安裝 gcc sudo yum -y install gcc 如果有安裝過 docker ,需要執行以下命令移除安裝 sudo yum remove docker do

centos 安裝 docker-ce

執行如下命令安裝即可 yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager  --add-repo  https://mirrors.aliyun.com/docker