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
映象加速器
- 阿里雲加速器(點選管理控制檯 -> 登入賬號(淘寶賬號) -> 右側映象工具 -> 映象加速器 -> 複製加速器地址)
- 網易雲加速器
https://hub-mirror.c.163.com
- 百度雲加速器
https://mirror.baidubce.com
- 中國科技大學 https://docker.mirrors.ustc.edu.cn
- ustc https://docker.mirrors.ustc.edu.cn
- Docker中國區官方映象 https://registry.docker-cn.com
請首先執行以下命令,檢視是否在
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
參考文件
https://yeasy.gitbook.io/docker_practice/install/centos