Docker CE部署


一、概述

Docker 在1.13版本之后,從2017年的3月1日開始,版本命名規則變為如下:

項目 說明
版本格式 YY.MM
Stable  每個季度發行
Edge版本 每個月發行

同時Docker划分為CE和EE。CE即社區版(免費,支持后期三個月),EE即企業版,強調安全,付費使用。

本實驗虛擬機CentOS7,采用阿里雲yum源安裝 

二、安裝Docker CE先決條件

官方各個版本安裝文檔:https://docs.docker.com/install/

系統要求

Docker CE支持64位版本CentOS 7,並且要求內核版本不低於3.10。CentOS 7滿足最低內核的要求,但由於內核版本比較低,部分功能(如overlay2存儲層驅動)無法使用,並且部分功能可能不太穩定。

查看系統內核版本

[root@linux-node1 ~]# cat /proc/version
Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
[root@linux-node1 ~]# uname -a
Linux linux-node1.example.com 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@linux-node1 ~]#

卸載舊版本

老版本的Docker被稱為docker或docker-engine。如果安裝了它們,請卸載他們以及相關的依賴項。

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine
[root@linux-node1 ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-selinux
No Match for argument: docker-engine-selinux
No Match for argument: docker-engine
No Packages marked for removal
示例一

如上示例一中所示報告說沒有安裝這些軟件包,就OK了。

/var/lib/docker/包括圖像,容器,卷和網絡的內容將被保留,現在調用Docker CE包docker-ce。

三、安裝Docker CE

使用存儲庫進行安裝

首次在新的主機上安裝Docker CE之前,需要設置Docker存儲庫,之后,您可以從存儲安裝和更新Docker。

設置存儲庫

  • 安裝所需要的包。yum-utils提供了yum-config-manager,device-mapper-persistent-datalvm2由需要 devicemapper存儲驅動程序。
[root@linux-node1 ~]# yum -y install yum-utils device-mapper-persistent-data lvm2

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

Complete!
[root@linux-node1 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

如果需要使用最新版的Docker CE使用以下命令(默認處於禁用狀態)

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

如果使用測試版本的Docker CE請使用以下命令(默認處於禁用狀態)

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

可以通過使用該標志運行命令來禁用邊緣測試存儲庫 要重新啟用它,請使用標志。以下命令禁用邊緣存儲庫。yum-config-manager--disable--enable

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

注意:從Docker 17.06開始,穩定版本也被推到邊緣並測試版本庫。

yum安裝Docker

[root@linux-node1 ~]# yum -y install docker-ce

Installed:
docker-ce.x86_64 0:18.03.1.ce-1.el7.centos

Dependency Installed:
container-selinux.noarch 2:2.55-1.el7

啟動Docker

[root@linux-node1 ~]# systemctl start docker

查看Docker運行狀態

[root@linux-node1 ~]# systemctl status docker

測試Docker是否安裝正確

[root@linux-node1 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
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/engine/userguide/

四、創建docker用戶組(此操作可以不執行)

docker守護程序綁定到一個Unix套接字而不是TCP端口。默認情況下,Unix套接字由root用戶擁有,其它用戶只能使用sudo來訪問它,該docker守護進程始終運行的root用戶。
處於安全考慮,一般Linux系統上不會直接使用root用戶,因此,更好的做法是將需要使用docker的用戶加入docker用戶組。當docker守護進程啟動時,它使得Unix套接字的所有權可以被docker組讀/寫

提示:該docker組授予root用戶等效的權限。有關會如何影響系統安全性的詳細信息,參閱:https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface

  •  創建docker組
groupadd docker
  • 將您的用戶添加到docker組中
usermod -aG docker $USER
  • 注銷並重新登錄,以便重新評估您的組成員資格。

    如果在虛擬機上進行測試,則可能需要重新啟動虛擬機才能使更改生效。

    在桌面Linux環境(如X Windows)上,完全退出會話並重新登錄。

  • 驗證您可以不使用運行docker命令sudo
docker run hello-world

五、內核參數修改

  • 添加內核參數

默認配置下,如果在CentOS使用Docker CE看到下面的這些警告信息:

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

 請添加內核配置參數以啟用這些功能

net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

然后重新加載sysctl.conf即可

sysctl -p

 六、配置加速器

建議安裝Docker之后配置國內鏡像加速。

官方文檔:https://docs.docker.com/registry/recipes/mirror/#run-a-registry-as-a-pull-through-cache

配置Docker守護進程

--registry-mirrordockerd手動啟動時傳遞選項,或者編輯/etc/docker/daemon.json 和添加registry-mirrors鍵和值,以使更改持久化。

{
  "registry-mirrors": ["https://<my-docker-mirror-host>"]
}

示例:中國鏡像

中國注冊鏡像的URL是registry.docker-cn.com通過在docker pull 命令中指定完整路徑(包括注冊表),您可以像從其他注冊表那樣從該鏡像中提取鏡像,例如:

$ docker pull registry.docker-cn.com/library/ubuntu

您可以添加"https://registry.docker-cn.com"registry-mirrors陣列中/etc/docker/daemon.json 以默認從China注冊表鏡像中拉取。

{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

保存文件並重新加載Docker以使更改生效。

[root@linux-node1 ~]# systemctl daemon-reload
[root@linux-node1 ~]# systemctl stop docker
[root@linux-node1 ~]# systemctl start docker
[root@linux-node1 ~]# systemctl status docker

或者,您可以使用--registry-mirror啟動參數配置Docker守護程序

dockerd --registry-mirror=https://registry.docker-cn.com

 


免責聲明!

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



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