Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Installing Docker on CentOS

Installing Docker on CentOS

Docker supports the following 64-bit CentOS versions:

The centos-extras repository must be enabled. It is enabled by default; if you have disabled it, you need to re-enable it.


Automatic Installation 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 their dependencies.

Run the following command to uninstall the old versions:

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 on a new host for the first time, you need to set up the Docker repository. After that, you can install and update Docker from the repository.

Set Up the Repository

Install the dnf-plugins-core package (which 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 (slower)

sudo

dnf config-manager

--add-repo

https:

//

download.docker.com

/

linux

/

centos

/

docker-ce.repo

You can run the following command to switch to the Tsinghua University mirror:

Tsinghua University Mirror

sed

-i

's+https://download.docker.com+https://mirrors.tuna.tsinghua.edu.cn/docker-ce+'

/

etc

/

yum.repos.d

/

docker-ce.repo

Reference: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 accept it if it does.

After a successful installation, start the Docker engine:

sudo systemctl start docker

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



sudo systemctl enable --now docker

The above command configures the Docker systemd service so that Docker starts automatically at boot.

Docker is not started by default after installation. The docker user group has been created, but it has no members.

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



sudo docker run hello-world

This command downloads a test image and runs it in a container; when the container runs, it prints a confirmation message and exits.

Uninstalling Docker

Remove the installation package:

yum remove docker-ce

Delete images, containers, configuration files, and so on:

rm -rf /var/lib/docker