Prerequisites
Operating system requirements
To install Docker Engine, you need a maintenance version of CentOS 7. The archive version is not supported or tested.
The centos-extras
library must be enabled. By default, this repository is enabled, but if it has been disabled, you need to re-enable it .
overlay2
It is recommended to use a storage driver.
Uninstall old version
Older Docker versions are called docker
OR docker-engine
. If these programs are already installed, please uninstall them and related dependencies.
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
If it is yum
reported that these packages are not installed, you can.
The contents ( /var/lib/docker/
including images, containers, volumes and networks) are retained. The Docker Engine package is now called docker-ce
.
installation method
You can install Docker Engine in different ways according to your needs:
-
Most users will set up a Docker repository and install from it to simplify installation and upgrade tasks. This is the recommended method.
-
Some users download and manually install RPM packages and manage the upgrade completely manually. This is very useful in situations such as installing Docker on a blank system without Internet access.
-
In testing and development environments, some users choose to use automated convenience scripts to install Docker.
Install using repository
Before installing Docker Engine on a new host for the first time, you need to set up a Docker repository. After that, you can install and update Docker from the repository.
Set up the repository
Install the yum-utils
software package (provide yum-config-manager
utilities) and set up a stable repository.
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Optional : Enable nightly or test repository.
These repositories are included in
docker.repo
the file above, but are disabled by default. You can enable them next to the stable repository. The following command enables the nightly repository.$ sudo yum-config-manager --enable docker-ce-nightly
To enable the test channel, run the following command:
$ sudo yum-config-manager --enable docker-ce-test
You can disable night or test repositories by running a command with a flag . To re-enable it, use this flag. The following command disables the night repository.
yum-config-manager
--disable
--enable
$ sudo yum-config-manager --disable docker-ce-nightly
Install Docker engine
-
Install the latest version of Docker Engine and container, or go to the next step to install a specific version:
$ sudo yum install docker-ce docker-ce-cli containerd.io
If you are prompted to accept the GPG key, verify that the fingerprint matches
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
, and if so, accept it.Have multiple Docker repositories?
If multiple Docker repositories are enabled, installing or updating without specifying the version in the
yum install
oryum update
command will always install the highest version possible, which may not suit your stability needs.Docker is installed but not yet started. The
docker
group has been created, but no users have been added to the group. -
To install a specific version of Docker Engine, list the available versions in the repository, then select and install:
One. List and sort the versions available in your repository. This example sorts the results by version number (from high to low) 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 CentOS version (
.el7
in this example, it is indicated by the suffix).b. Install a specific version by its fully qualified package name, which is the package name (
docker-ce
) plus the version string (second column), from the first colon (:
) to the first hyphen, with a hyphen (-
) Separate. Fordocker-ce-18.09.1
example, .sudo docker-ce-cli-<VERSION_STRING> containerd.io # 例如: yum install docker-ce-18.09.9 docker-ce-cli-18.09.9 containerd.io # 安装最新版本: # yum -y install docker-ce
The following errors may appear (click the error jump to see the solution)
docker
group has been created, but no users have been added to the group. -
Start Docker
$ sudo systemctl start docker
-
Run the
hello-world
image to verify that Docker Engine is installed correctly.$ sudo docker run hello-world
This command downloads the test image and runs it in the container. When the container is running, it will print an informational message and exit.
Docker Engine is installed and running. You need to use sudo
to run Docker commands. Proceed to post-Linux installation to allow non-privileged users to run Docker commands and other optional configuration steps.
Upgrade Docker engine
To upgrade Docker Engine, follow the installation instructions and select the new version to install.
Install from package
If you can't use Docker's repository to install Docker, you can download the .rpm
distribution's files and install it manually. Every time you want to upgrade Docker Engine, you need to download a new file.
-
Go to https://download.docker.com/linux/centos/ and select your CentOS version. Then browse
x86_64/stable/Packages/
and download.rpm
the file of the Docker version you want to install.Note : To install night or test (pre-release) packages,
stable
change the word in the above URL tonightly
ortest
. -
Install Docker Engine and change the path below to the path where you downloaded the Docker package.
$ sudo yum install /path/to/package.rpm
Docker is installed but not yet started. The
docker
group has been created, but no users have been added to the group. -
Start Docker
$ sudo systemctl start docker
-
Run the
hello-world
image to verify that Docker Engine is installed correctly.$ sudo docker run hello-world
This command downloads the test image and runs it in the container. When the container is running, it will print an informational message and exit.
Docker Engine is installed and running. You need to use sudo
to run Docker commands. Continue to perform the Linux post-installation steps to allow non-privileged users to run Docker commands and other optional configuration steps.
Upgrade Docker engine
To upgrade Docker Engine, download the updated package file and use instead of repeating the installation process and pointing to the new file.yum -y upgrade
yum -y install
Use convenient scripts
Docker provides convenient scripts on get.docker.com and test.docker.com to install the edge version and test version of Docker Engine-Community into the development environment quickly and non-interactively. The source code of the script is in the docker-install
repository . It is not recommended to use these scripts in a production environment , and before using them, you should understand the potential risks:
- The script needs to run
root
or havesudo
privileges. Therefore, before running the script, you should carefully check and review the script. - These scripts try to detect the Linux distribution and version, and configure the package management system for you. In addition, the script does not allow you to customize any installation parameters. From the perspective of Docker or your own organization's guidelines and standards, this may result in unsupported configurations.
- These scripts will install all the dependencies and recommendations of the package manager without confirmation. Depending on the current configuration of the host, this may install a large number of packages.
- The script does not provide an option to specify which version of Docker to install, but instead installs the latest version released in the "edge" channel.
- If you have used other mechanisms to install Docker on the host, please do not use convenience scripts.
This example uses the script on get.docker.com to install the latest version of Docker Engine-Community on Linux . To install the latest test version, use test.docker.com instead . In each of the following commands, substituted at each occurrence get
with test
.
Warning :
Before running locally, be sure to check the script downloaded from the Internet.
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
<output truncated>
If you want to use Docker as a non-root user, you should now consider adding users to the "docker" group in a way similar to the following:
sudo usermod -aG docker your-user
Please remember to log out and log in again to take effect!
Warning :
After adding users to the "Dockers" group, they can run containers, which can be used to obtain root privileges on the Docker host. For more information, please refer to Docker Daemon Attack Surface .
Docker Engine-Community has been installed. It will automatically start DEB
on the distribution-based version. On RPM
distribution-based systems, you need to manually start it using the corresponding systemctl
or service
command. As the message indicates, by default, non-root users cannot run Docker commands.
Matters needing attention :
To install Docker without root privileges , see Run the Docker daemon as a non-root user (unrooted mode) .
Rootless mode is currently available as an experimental feature.
Upgrade Docker after using the convenient script
If you installed Docker using a convenient script, you should use the package manager to upgrade Docker directly. There is no benefit to re-running the convenience script, and it may cause problems if you try to re-add a repository that has already been added to the host.
Uninstall Docker
Query delete docker
1. List the specific name of the docker package
$ sudo yum list installed | grep docker
containerd.io.x86_64 1.2.4-3.1.el7
docker-ce.x86_64 3:18.09.3-3.el7
docker-ce-cli.x86_64 1:18.09.3-3.el7
2. Delete docker
$ sudo yum -y remove containerd.io.x86_64 \
docker-ce.x86_64 \
docker-ce-cli.x86_64
Delete docker directly
sudo yum remove docker \
docker-io \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
-
Uninstall Docker Engine, CLI and Containerd packages:
$ sudo yum remove docker-ce docker-ce-cli containerd.io
-
Images, containers, volumes, or custom configuration files on the host will not be deleted automatically. To delete all images, containers and volumes:
$ sudo rm -rf /var/lib/docker
You must manually delete all edited configuration files.