目录
1.准备
-
OS requirements
To install Docker Engine, you need a maintained version of CentOS 7 or 8. Archived versions aren’t supported or tested.
The
centos-extras
repository must be enabled. This repository is enabled by default, but if you have disabled it, you need to re-enable it.The
overlay2
storage driver is recommended.
- Uninstall old versions
Older versions of Docker were called
docker
ordocker-engine
. If these are installed, uninstall them, along with associated dependencies.
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2.安装
三种安装方法
You can install Docker Engine in different ways, depending on your needs:
Most users set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.
Some users 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, some users choose to use automated convenience scripts to install Docker.
(1)使用远程仓库在线安装
- 配置yum仓库
Install the
yum-utils
package (which provides theyum-config-manager
utility) and set up the stable repository.
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- 安装docker engine
安装最新版本
$ sudo yum install docker-ce docker-ce-cli containerd.io
安装指定版本
a. List and sort the versions available in your repo. This example sorts results by version number, highest to lowest, and is truncated:
$ yum list docker-ce --showduplicates | sort -r docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
The list returned depends on which repositories are enabled, and is specific to your version of CentOS (indicated by the
.el7
suffix in this example).b. Install a specific version by its fully qualified package name, which is the package name (
docker-ce
) plus the version string (2nd column) starting at the first colon (:
), up to the first hyphen, separated by a hyphen (-
). For example,docker-ce-18.09.1
.$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
- 启动docker
$ sudo systemctl start docker
- 验证正确安装
$ sudo docker run hello-world
(2)通过rpm 包离线安装
Go to https://download.docker.com/linux/centos/ and choose your version of CentOS. Then browse to
x86_64/stable/Packages/
and download the.rpm
file for the Docker version you want to install.
以centos8.4为例,需要下载下面4个包
- 安装docker engine
切换到rpm包下载的目录,
yum install ./containerd.io-1.4.3-3.1.el8.x86_64.rpm ./docker-ce-cli-20.10.0-3.el8.x86_64.rpm ./docker-ce-20.10.0-3.el8.x86_64.rpm ./docker-ce-rootless-extras-20.10.0-3.el8.x86_64.rpm
- 启动docker
sudo systemctl start docker
sudo systemctl status docker
- 验证正确安装
Verify that Docker Engine is installed correctly by running the
hello-world
image.$ sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
(3)脚本安装
参考:https://docs.docker.com/engine/install/centos/#install-using-the-convenience-script
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
3.卸载Docker Engine
a.Uninstall the Docker Engine, CLI, and Containerd packages:
$ sudo yum remove docker-ce docker-ce-cli containerd.io
b.Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
$ sudo rm -rf /var/lib/docker
参考:
1.官网centos安装教程
https://docs.docker.com/engine/install/centos/
2.安装教程