Instructions for installing Docker on CentOS

Instructions for installing Docker on CentOS

Instructions for installing Docker on CentOS

There are several ways to install Docker on CentOS. You can choose to install it automatically using the official installation script, install it using a domestic mirror source, or install it manually.

Here are the steps to automatically install Docker using the official installation script:

  1. Open a terminal and log in to the CentOS server with root privileges.
  2. Run the following commands to download and execute the official installation script:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

This command will download the installation script from the official website and automatically install Docker. --mirror AliyunThe parameter specifies the use of Alibaba Cloud mirror source, which can speed up the download speed.

In addition, you can also choose to use the domestic Daocloud mirror source for installation. The method is as follows:

curl -sSL https://get.daocloud.io/docker | sh

The above command will download the installation script from Daocloud and execute the installation.

If you want to do a manual installation, you can follow these steps:

  1. Uninstall the old version of Docker. If you have installed an older version of Docker before, you can uninstall it by running the following command:
sudo yum remove docker \
  docker-client \
  docker-client-latest \
  docker-common \
  docker-latest \
  docker-latest-logrotate \
  docker-logrotate \
  docker-engine
  1. Install Docker Engine-Community. First, install the required packages and dependencies. Run the following command:
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

These packages provide the dependencies required to install Docker Engine-Community.

  1. Set up a Docker repository. Depending on your needs, you can choose to use the official source address, Alibaba Cloud source address, or Tsinghua University source address. The following is an example command to set up a stable repository:
  • Use the official source address (slower):
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • Use Alibaba Cloud source address:
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • Use Tsinghua University source address:
sudo yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
  1. Install Docker Engine-Community. Run the following commands to install the latest version of Docker Engine-Community and containerd:
sudo yum install docker-ce docker-ce-cli containerd.io

If you are prompted to accept the GPG key, select Yes.

  1. Start the Docker service. Run the following command to start the Docker service:
sudo systemctl start docker

Now, you have successfully installed Docker and started the Docker service.

In order to verify that Docker Engine-Community is installed correctly, you can run a simple Docker container by running the following command:

sudo docker run hello-world

This will download and run a container image named hello-world. If everything goes well, you will see relevant prompts.

Please note that the above are common methods and steps for installing Docker on CentOS. There may be some minor differences depending on your specific situation and needs. If you require more detailed information, please refer to the following cited sources:

Reference sources:

  1. Get Docker

Recommend a free tutorial from Lingsheng Academy. I personally think the teacher’s lecture is good and I would like to share it with you. If you are interested, you can check it out: [Linux, Nginx, DPDK and other technical content, Click to learn now.

Guess you like

Origin blog.csdn.net/weixin_36184908/article/details/131117386
Recommended