目录
官方文档
Install Docker Engine on CentOS | Docker Documentation
Installation methods
You can install Docker Engine in different ways, depending on your needs:
-
You can set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.
-
You can download the RPM package and install it manually and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.
-
In testing and development environments, you can use automated convenience scripts to install Docker.
Docker 官方提供了三种方式,分别是仓库安装、RPM包安装和 scripts 脚本安装。
官方推荐用 仓库安装。
Install using the repository
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
在你开始第一次为一台新的主机安装 Docker 引擎之前,你需要设置 Docker 仓库。从那以后,你可以从仓库安装和更新 Docker。
Set up the repository
Install the yum-utils
package (which provides the yum-config-manager
utility) and set up the repository.
1、安装 yum-utils 软件包
sudo yum install -y yum-utils
提示 完毕!就说明已经安装完成
2、设置仓库
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
因为 https://download.docker.com 是国外的网站,所以经常会连不上
所以我们使用国内阿里云的镜像仓库
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3、安装 Docker 引擎
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
会有两次选择,全部选y就可以
完毕!
4、启动 Docker 服务
sudo systemctl start docker
5、测试
测试1:看看 docker 版本
docker version
测试2:运行 hello-world 镜像
sudo docker run hello-world
执行 docker run image_name
如果本地有镜像,直接生成容器实例;如果本地没有镜像,从远程仓库拉取镜像,然后生成容器实例。输出【Hello from Docker! This message shows that ... correctly】这段提示以后,hello world就会停止运行,容器自动终止。
6、卸载 Docker
停掉我们 Docker 后台服务
systemctl stop docker
卸载
sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
删除本地数据
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd