1. 环境准备
-
阿里云服务器Centos 7.9
-
使用Xshell远程连接服务器
[root@zero /]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
2.Docker安装
- 官方文档地址:https://docs.docker.com/engine/install/centos/
- 卸载旧版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 需要安装
yum-utils
sudo yum install -y yum-utils
- 配置阿里云仓库
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- 安装docker的社区版本 docker-ce 社区版 docker-ee 企业版
# 最新版本
sudo yum install docker-ce docker-ce-cli containerd.io
# 安装指定版本
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
- 启动docker
sudo systemctl start docker
- 查看当前docker的版本
[root@zero /]# docker version
Client: Docker Engine - Community
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:45:41 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:44:05 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
- 拉取hello-world镜像
[root@zero /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
- 查看镜像
[root@zero /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 3 months ago 13.3kB
- docker 的默认工作路径:
/var/lib/docker
3.阿里云镜像加速
登录阿里云找到容器镜像服务,在镜像加速其中选择自己的系统,修改配置文件再重启docker即可。
4.卸载docker引擎
- 卸载 Docker Engine、CLI 和 Containerd 包
sudo yum remove docker-ce docker-ce-cli containerd.io
- 主机上的映像、容器、卷或自定义配置文件不会自动删除。删除所有镜像、容器和卷:
sudo rm -rf /var/lib/docker #docker的默认地址
sudo rm -rf /var/lib/containerd