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

Docker CE安裝

準備工作

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

卸載舊版本

​ 舊版本的 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

Centos Docker CE在線安裝

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

使用 yum 安裝

執行以下命令安裝依賴包:

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

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

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

# 阿里源
$ 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版本:

$ 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 下載地址2

安裝

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

1. yum安裝

​ 建議使用yum方式安裝,yum安裝過程中會下載相應的軟件依賴,可以省去很多麻煩

# 使用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/

參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章