链接: docker 官方文档
系统要求
要安装 Docker Engine,您需要 CentOS 7、CentOS 8(流)或 CentOS 9(流)的维护版本。存档版本不受支持或测试。
查看系统版本命令 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"
安装
- 第一步卸载旧版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 设置存储库 安装 镜像仓库使用阿里的
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- 安装Docker 引擎
安装之前先更新 yum
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
- 启动 Docker。
systemctl start docker
hello-world 通过运行映像来验证 Docker 引擎是否已正确安装。
docker run hello-world
启动成功
- 卸载 Docker 引擎
yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
主机上的映像、容器、卷或自定义配置文件不会自动删除。要删除所有映像、容器和卷:
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
/var/lib/docker 是docker的默认工作路径
- 查看下载的镜像
docker images
- 阿里云镜像加速 可自行百度自己
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://hmql3exh.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker