Docker CE 18.06在線安裝和RPM包安裝

Docker CE安裝

準備工做

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

卸載舊版本

​ 舊版本的 Docker 稱爲 docker 或者 docker-engine,使用如下命令卸載舊版本:python

$ 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

Centos Docker CE在線安裝

警告:切勿在沒有配置 Docker YUM 源的狀況下直接使用 yum 命令安裝 Docker.

使用 yum 安裝

執行如下命令安裝依賴包:linux

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

鑑於國內網絡問題,建議使用下面的阿里源。git

執行下面的命令添加 yum 軟件源:docker

# 阿里源
$ sudo yum-config-manager \ 
    --add-repo \ 
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 中科大源
# $ sudo yum-config-manager \
#     --add-repo \
#     https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
    
# 官方源
# $ sudo yum-config-manager \
#     --add-repo \
#     https://download.docker.com/linux/centos/docker-ce.repo

查看Docker版本:shell

$ sudo yum list docker-ce --showduplicates

安裝 Docker CE

# 更新本地yum包緩存
$ sudo yum makecache fast
# 安裝最新版docker ce
$ sudo yum install docker-ce
# 安裝指定版本docker ce,加上指定版本號
# $ sudo yum install docker-ce-18.03.0.ce

Centos Docker CE rpm離線安裝

下載rpm包

​ docker-ce-18.06.1.ce-3.el7.x86_64.rpm 下載地址1 下載地址2json

安裝

​ 下載完上面的rpm包後進行安裝,會涉及到一些軟件依賴的問題,能夠分狀況選擇如下方式進行安裝:ubuntu

1. yum安裝

​ 建議使用yum方式安裝,yum安裝過程當中會下載相應的軟件依賴,能夠省去不少麻煩centos

# 使用yum命令安裝
$ sudo yum -y install docker-ce-18.06.1.ce-3.el7.x86_64.rpm
2. 手動下載依賴rpm包安裝

​ 若是網絡問題沒法使用yum方式安裝,能夠手動下載軟件依賴rpm包進行安裝緩存

​ 通過屢次試驗,所需包以下:

  1. container-selinux-2.74-1.el7.noarch.rpm 下載地址
  2. libselinux-2.5-14.1.el7.x86_64.rpm 下載地址
  3. libselinux-python-2.5-14.1.el7.x86_64.rpm 下載地址
  4. libselinux-utils-2.5-14.1.el7.x86_64.rpm 下載地址
  5. libsemanage-2.5-14.el7.x86_64.rpm 下載地址
  6. libsemanage-python-2.5-14.el7.x86_64.rpm 下載地址
  7. libsepol-2.5-10.el7.x86_64.rpm 下載地址
  8. policycoreutils-2.5-29.el7.x86_64.rpm 下載地址
  9. policycoreutils-python-2.5-29.el7.x86_64.rpm 下載地址
  10. selinux-policy-3.13.1-229.el7.noarch.rpm 下載地址
  11. selinux-policy-targeted-3.13.1-229.el7.noarch.rpm 下載地址
  12. setools-libs-3.3.8-4.el7.x86_64.rpm 下載地址

​ 若是上面的地址沒法下載,我這裏有一份打包好的資源 docker-ce-18.06 rpm軟件依賴包

​ 下載上述依賴包和docker ce的rpm包,放在同一目錄下,執行安裝命令:

$ sudo rpm -ivh softPath/*.rpm --nodeps --force

安裝成功後設置

啓動Docker CE

# 設置開機啓動docker ce
$ sudo systemctl enable docker
# 啓動docker ce
$ sudo systemctl start docker

創建 docker 用戶組

# 創建docker組
$ sudo groupadd docker
# 講當前用戶加入docker組
$ sudo usermod -aG docker $USER

退出當前終端並從新登陸,進行以下測試。

測試 Docker 是否安裝正確

# 啓動hello-world容器
$ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete 
Digest: sha256:b3a26e22bf55e4a5232b391281fc1673f18462b75cdc76aa103e6d3a2bce5e77
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/

若能正常輸出以上信息,則說明安裝成功。

設置鏡像加速器

國內網絡訪問docker官方鏡像可能會比較慢

https://registry.docker-cn.com 爲Docker官方提供的國內加速器,應該算是體驗最好之一的加速器了

https://reg-mirror.qiniu.com 七牛雲加速器

/etc/docker/daemon.json 中寫入以下內容(若是文件不存在請新建該文件)

{
    "registry-mirrors": [
        "https://registry.docker-cn.com"
    ]
}
注意,必定要保證該文件符合 json 規範,不然 Docker 將不能啓動。
# 重啓docker服務
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

檢查加速器是否生效

配置加速器以後,若是拉取鏡像仍然十分緩慢,請手動檢查加速器配置是否生效,在命令行執行 docker info,若是從結果中看到了以下內容,說明配置成功。

Registry Mirrors:
 https://registry.docker-cn.com/

參考

相關文章
相關標籤/搜索