1. 程式人生 > 其它 >Docker 安裝與解除安裝

Docker 安裝與解除安裝

Docker解除安裝與安裝

解除安裝舊的版本

解除安裝

yum -y remove docker-ce docker-cli-io containerd.io
rm -rf var /var/lib/docker
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

安裝 yum-utils 包

安裝yum-utils包(提供yum-config-manager實用程式)並設定穩定的儲存庫。

 sudo yum install -y yum-utils
[root@localhost ~]#  sudo yum install -y yum-utils
已載入外掛:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
軟體包 yum-utils-1.1.31-54.el7_8.noarch 已安裝並且是最新版本
無須任何處理

設定儲存庫

鑑於國內網路問題,強烈建議使用國內源

sudo yum-config-manager \
   --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

官方源

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost ~]# sudo yum-config-manager \
>     --add-repo \
>     https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已載入外掛:fastestmirror, product-id, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

安裝 docker

安裝 docker

sudo yum install docker-ce docker-ce-cli containerd.io
[root@localhost ~]#  yum install docker-ce docker-ce-cli containerd.io
已載入外掛:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 containerd.io.x86_64.0.1.4.9-3.1.el7 將被 安裝
---> 軟體包 docker-ce.x86_64.3.20.10.7-3.el7 將被 安裝
--> 正在處理依賴關係 docker-ce-rootless-extras,它被軟體包 3:docker-ce-20.10.7-3.el7.x86_64 需要
---> 軟體包 docker-ce-cli.x86_64.1.20.10.7-3.el7 將被 安裝
--> 正在處理依賴關係 docker-scan-plugin(x86-64),它被軟體包 1:docker-ce-cli-20.10.7-3.el7.x86_64 需要
--> 正在檢查事務
---> 軟體包 docker-ce-rootless-extras.x86_64.0.20.10.7-3.el7 將被 安裝
---> 軟體包 docker-scan-plugin.x86_64.0.0.8.0-3.el7 將被 安裝
--> 解決依賴關係完成
……省略

啟動 docker

 sudo systemctl start docker

檢視 docker 狀態

 sudo systemctl status docker

測試 docker

通過執行hello world映像驗證Docker引擎是否已正確安裝。如下說明安裝成功

[root@localhost ~]# docker run  hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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/

開機自啟

systemctl enable docker

映象加速器

請首先執行以下命令,檢視是否在 docker.service 檔案中配置過映象地址。

systemctl cat docker | grep '\-\-registry\-mirror'

如果該命令有輸出,那麼請執行 $ systemctl cat docker 檢視 ExecStart= 出現的位置,修改對應的檔案內容去掉 --registry-mirror 引數及其值,並按接下來的步驟進行配置。

如果以上命令沒有任何輸出,那麼就可以在 /etc/docker/daemon.json 中寫入如下內容(如果檔案不存在請新建該檔案):

{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com"
  ]
}

注意,一定要保證該檔案符合 json 規範,否則 Docker 將不能啟動。

重啟 docker 服務

sudo systemctl daemon-reload
sudo systemctl restart docker

參考文件

Docker 官方 CentOS 安裝文件

https://yeasy.gitbook.io/docker_practice/install/centos

本文來自部落格園,作者:天葬,轉載請註明原文連結:https://www.cnblogs.com/bxmm/p/15093113.html