All Products
Search
Document Center

Elastic Compute Service:Install Docker

Last Updated:Nov 08, 2024

Docker is an open platform on which you can develop, publish, and run applications. This topic describes how to install and use Docker on an Elastic Compute Service (ECS) instance.

Install Docker

Alibaba Cloud Linux 3

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    sudo dnf -y remove \
    docker-ce \
    containerd.io \
    docker-ce-rootless-extras \
    docker-buildx-plugin \
    docker-ce-cli \
    docker-compose-plugin
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo dnf -y update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo dnf config-manager --add-repo=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo dnf config-manager --add-repo=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
      sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
  3. Install the Dandified YUM (DNF) repository plug-in that is exclusive to Alibaba Cloud Linux 3.

    sudo dnf -y install dnf-plugin-releasever-adapter --repo alinux3-plus
  4. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  5. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  6. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

Alibaba Cloud Linux 2

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    sudo yum -y remove \
    docker-ce \
    containerd.io \
    docker-ce-rootless-extras \
    docker-buildx-plugin \
    docker-ce-cli \
    docker-compose-plugin
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo yum -y update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
      sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
  3. Install the Yellowdog Updater Modified (YUM) repository plug-in that is exclusive to Alibaba Cloud Linux 2.

    sudo yum install yum-plugin-releasever-adapter --disablerepo=* --enablerepo=plus
  4. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  5. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  6. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

CentOS 7.x

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    sudo yum -y remove \
    docker-ce \
    containerd.io \
    docker-ce-rootless-extras \
    docker-buildx-plugin \
    docker-ce-cli \
    docker-compose-plugin
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo yum -y update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
      sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
  3. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  5. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

CentOS 8.x

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    sudo dnf -y remove \
    docker-ce \
    containerd.io \
    docker-ce-rootless-extras \
    docker-buildx-plugin \
    docker-ce-cli \
    docker-compose-plugin
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo dnf -y update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo dnf config-manager --add-repo=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo dnf config-manager --add-repo=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
      sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
  3. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  5. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

Ubuntu

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    for pkg in docker.io docker-buildx-plugin docker-ce-cli docker-ce-rootless-extras docker-compose-plugin docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove -y $pkg; done
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo apt-get update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
      sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
      sudo add-apt-repository -y "deb [arch=$(dpkg --print-architecture)] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
      sudo curl -fsSL http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu/gpg | apt-key add -
      sudo add-apt-repository -y "deb [arch=$(dpkg --print-architecture)] http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  3. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  5. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

Debian

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    for pkg in docker.io docker-buildx-plugin docker-ce-cli docker-ce-rootless-extras docker-compose-plugin docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove -y $pkg; done
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo apt-get update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
      sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add -
      sudo add-apt-repository -y "deb [arch=$(dpkg --print-architecture)] https://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -cs) stable"
      sudo apt-get update
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
      sudo curl -fsSL http://mirrors.cloud.aliyuncs.com/docker-ce/linux/debian/gpg | apt-key add -
      sudo add-apt-repository -y "deb [arch=$(dpkg --print-architecture)] http://mirrors.cloud.aliyuncs.com/docker-ce/linux/debian $(lsb_release -cs) stable"
      sudo apt-get update
  3. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  5. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

Fedora

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    sudo dnf -y remove \
    docker-ce \
    containerd.io \
    docker-ce-rootless-extras \
    docker-buildx-plugin \
    docker-ce-cli \
    docker-compose-plugin
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo dnf -y update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo dnf config-manager --add-repo=https://mirrors.aliyun.com/docker-ce/linux/fedora/docker-ce.repo
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo dnf config-manager --add-repo=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/fedora/docker-ce.repo
      sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
  3. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  5. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

Red Hat

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    sudo yum -y remove \
    docker-ce \
    containerd.io \
    docker-ce-rootless-extras \
    docker-buildx-plugin \
    docker-ce-cli \
    docker-compose-plugin
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo dnf -y update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/rhel/docker-ce.repo
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.cloud.aliyuncs.com/docker-ce/linux/rhel/docker-ce.repo
      sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
  3. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  5. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

Anolis OS

Before you install the latest version of Docker, run the docker -v command to query the current Docker version. If the command output indicates that the command is unavailable, Docker is not installed. If you installed an earlier version of Docker, you must uninstall Docker and related components.

Uninstall an earlier version of Docker

  1. Run the following command to uninstall the earlier version of Docker and related software packages. This command allows you to uninstall all Docker-related programs.

    Note

    If the system prompts that specific software packages that you want to remove are not installed, you did not install the software packages.

    sudo yum -y remove \
    docker-ce \
    containerd.io \
    docker-ce-rootless-extras \
    docker-buildx-plugin \
    docker-ce-cli \
    docker-compose-plugin
  2. Manually delete Docker-related data. Docker is stored in the /var/lib/docker/ directory. When Docker is uninstalled, information about images, containers, volumes, and networks is not automatically deleted. If you do not require the data, manually delete the data.

  1. Update your package management tool.

    sudo yum -y update
  2. Add an Alibaba Cloud repository to your instance. This repository contains the Docker software package that allows you to run commands to install and update Docker.

    • If your instance can access the Internet, run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    • If your instance cannot access the Internet, use the virtual private cloud (VPC) endpoint and run the following command:

      sudo wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
      sudo sed -i 's|https://mirrors.aliyun.com|http://mirrors.cloud.aliyuncs.com|g' /etc/yum.repos.d/docker-ce.repo
  3. Install the Docker Community Edition (Docker-CE), the container runtime named containerd.io, and Docker building and orchestration plug-ins.

    sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Start Docker and enable the Docker daemon to start on system startup. This ensures that the Docker service automatically starts every time the system starts.

    Note

    If an error occurs when you run the systemctl command, troubleshoot the error. For more information, see What do I do if an error occurs when I run the systemctl command on a Linux instance?

    sudo systemctl start docker
    sudo systemctl enable docker
  5. Query the Docker version to check whether Docker is installed.

    sudo docker -v

    If the following command output is returned, Docker is installed on the ECS instance.image

Create a simple web application image

The following example describes how to create a simple web application image by using an NGINX image as the base image.

Preparations

On your instance that can access the Internet, run the following docker pull command to obtain the most recent NGINX image:

sudo docker pull nginx:latest

Create an image

  1. Create the Dockerfile file. The Dockerfile file is a special text file that defines how to build a Docker image. In the Dockerfile file, specify a base image for Docker, and specify the software packages to install and settings to configure on the base image.

    sudo touch Dockerfile
  2. Modify the created Dockerfile file by adding content.

    FROM nginx:latest
    RUN echo 'Hello World!' > /usr/share/nginx/html/index.html
  3. Use the Dockerfile file to build your image.

    sudo docker build . -t hello-world:latest
  4. Create a container based on your new image and name the container hello-world.

    sudo docker run -d -p 80:80 --name hello-world hello-world:latest
  5. Check whether the image is created. Run the curl http://localhost command. If hello world! is returned, the image is created as expected.

FAQs

What do I do if an error occurs when I run the dnf config-manager command on a Linux ECS instance?

  • Problem description: When you run the dnf config-manager command on a Linux ECS instance, the following error message appears:

    /usr/lib/python3/dist-packages/dnf/const.py:22: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives.
  • Cause: The DNF version is outdated.

  • Solution: Run the sudo dnf update dnf command to update the DNF package to the latest version and re-install Docker.

What do I do if an error occurs when I run the dnf install docker-ce command on a Linux ECS instance?

Problem description 1: When you run the dnf -y install docker-ce command on a Linux ECS instance, the following error message appears:

(8-9/12): docker-ce-24.0.7-1.el8.x86_64.rpm 38% [================- ] 8.2 MB/s | 38 MB 00:07 ETA
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: Error downloading packages:
containerd.io-1.6.26-3.1.el8.x86_64: Cannot download, all mirrors were already tried without success.

Cause: The installation package in the cache is outdated.

Solution: Run the sudo dnf clean packages command to clear the installation package in the cache and re-install Docker.

Problem description 2: When you run the dnf -y install docker-ce command on a Linux ECS instance, the following error messages appear:

CentOS- Base                                                                                                                         0.0  B/s |   0  B     00:30    
Errors during downloading metadata for repository 'base':
  - Curl error (6): Couldn't resolve host name for http://mirror.centos.org/os/BaseOS/x86_64/os/repodata/repomd.xml [Could not resolve host: mirror.aliyuncs.com]
  - Curl error (28): Timeout was reached for http://mirror.centos.org/os/BaseOS/x86_64/os/repodata/repomd.xml [Connection timed out after 30000 milliseconds]
  - Curl error (6): Couldn't resolve host name for http://mirror.centos.org/os/BaseOS/x86_64/os/repodata/repomd.xml [Could not resolve host: mirror.cloud.aliyuncs.com]
Error: Failed to download metadata for repo 'base': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

Cause: An expired CentOS 8 repository is used.

Solution: Perform the following operations to replace the expired CentOS 8 repository with an available repository provided by Alibaba Cloud:

# Back up the expired repository. 
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# Download the CentOS-Base.repo file provided by Alibaba Cloud to the /etc/yum.repos.d/ directory. 
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.aliyuncs.com/repo/Centos-vault-8.5.2111.repo
# Replace the repository addresses in the Alibaba Cloud repository with repository addresses that are accessible to the ECS instance. 
sudo sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/CentOS-Base.repo && sudo sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/CentOS-Base.repo && sudo sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo
# Clear the existing installation package in the cache and generate a new installation package in the cache based on the repository that you specified. 
sudo yum clean all && sudo yum makecache

Re-install Docker after you perform the preceding operations.

Note

If you do not want to use the repository provided by Alibaba Cloud, comment out the unavailable repository addresses in the /etc/yum.repos.d/CentOS-Base.repo file and re-install Docker.

References