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
鏡像加速器
- 阿里云加速器(點擊管理控制臺 -> 登錄賬號(淘寶賬號) -> 右側鏡像工具 -> 鏡像加速器 -> 復制加速器地址)
- 網易云加速器
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
參考文檔
哇!又賺了一天人民幣

浙公網安備 33010602011771號