CentOS Docker Installation

Docker supports the following 64-bit CentOS versions:

  • CentOS 9 (stream)
  • Later versions...

Must enable the centos-extras repository, which is enabled by default. If you have disabled it, you need to re-enable it.


Install automatically using the official installation script.

The installation command is as follows:

$ curl -fsSL https://get.docker.com -o install-docker.sh
$ sudo sh install-docker.sh

Manual installation

Uninstall old versions

Older Docker versions were called docker or docker-engine. If these programs are installed, uninstall them along with related dependencies.

Run the following command to uninstall the old version:

sudo dnf remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Installation

Install using the Docker repository.

Before installing Docker for the first time on a new host, you need to set up the Docker repository. After that, you can install and update Docker from the repository.

Set up repository

Install the dnf-plugins-core package (provides commands for managing DNF repositories), and set up the repository.

sudo dnf -y install dnf-plugins-core

Use the following command to set up the stable repository.

Use the official source address (relatively slow).

sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

You can execute the following command to switch to the Tsinghua University mirror source:

Tsinghua University mirror source

sed -i 's+https://download.docker.com+https://mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

Reference address:https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/

Installation

Run the following command to install Docker:

sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

If prompted to accept the GPG key, verify that the fingerprint matches 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, and if it matches, accept it.

After installation succeeds, start the Docker engine:

sudo systemctl start docker

If you want Docker to start at system boot, you can use the following command:

sudo systemctl enable --now docker

The above command configures Docker's systemd service to automatically start Docker at system boot.

After Docker is installed, it is not started by default. Also, the docker user group has already been created, but there are no users in that group.

Run the following command to verify that the installation was successful:

sudo docker run hello-world

This command will download a test image and run it in a container. When the container runs, it will print a confirmation message and exit.

Uninstall docker

Delete the installation package:

yum remove docker-ce

Remove images, containers, configuration files, and other content:

rm -rf /var/lib/docker
other extensions