[Software installation] Install docker container in Centos system (Huawei Cloud HECS Yunyao Server)

This article mainly introduces the installation of docker containers (Huawei Cloud HECS Yunyao Server) in Centos systems.

Table of contents

1. Install docker

1.1. Uninstall the old version of docker

1.2. Update repo image

1.3. Install dependency packages

1.4. Add docker-ce image

1.5. Install docker-ce

1.6. Check the docker installation version

1.7. Start the docker service

1.8. Stop and restart the docker service


1. Install docker

1.1. Uninstall the old version of docker

Before installation, first execute the following command to delete the old version of docker.

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

1.2. Update repo image

Enter the /etc/yum.repos.d directory and check whether there is a docker-related image. If so, delete the corresponding docker image source first.

# 进入目录,查看是否存在docker镜像
cd /etc/yum.repos.d/

If you find a docker-related repo image, you need to delete it first.

1.3. Install dependency packages

Install yun-utils, lvm2, device-mapper-persistent-data related dependency packages and execute the following command:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

After executing the command, the following error may appear, as shown in the figure below:

If the above error occurs, you can solve it in the following ways. Execute the following command to update the centos image library.

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

After the image is downloaded successfully, you can view the corresponding centos image.

Execute first[yum clean all] command, then execute[yum makecache]Update cached command.

After the cache update is successful, execute again[sudo yum install -y --skip-broken yum-utils device-mapper-persistent-data lvm2] command, the installation will be successful at this time.

1.4. Add docker-ce image

Execute the following command to add the docker-ce image to the system (Note: The Alibaba Cloud image used here cannot be used directly because the docker image is abroad< /span>).

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

As shown below:

1.5. Install docker-ce

Execute[sudo yum install docker-ce docker-ce-cli containerd.io]Install docker. If an error occurs during execution:

The error log is as follows:

Repository base is listed more than once in the configuration
Docker CE Stable - x86_64                                                                                               9.1 kB/s | 2.3 kB     00:00
Errors during downloading metadata for repository 'docker-ce-stable':
  - Status code: 404 for https://mirrors.aliyun.com/docker-ce/linux/centos/2.0/x86_64/stable/repodata/repomd.xml (IP: 218.77.199.215)
Error: Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

This can be solved by:

  • Enter the /etc/yum.repo.d directory and use [vim docker-ce.repo] to modify the contents of the docker-ce.repo file.
  • Modify $releaserver in baseUrl to [8].

As shown below:

After the modification is successful, re-execute the [sudo yum install docker-ce docker-ce-cli containerd.io] command. At this time, control The platform will start downloading docker-related things and will prompt whether to continue. Just enter y.

After entering y, it will start downloading docker related content from Alibaba Cloud's mirror warehouse.

1.6. Check the docker installation version

After docker is installed successfully, you can check the docker version through the [docker --version] command.

1.7. Start the docker service

Execute the following command to first create a soft link for the docker service and start the docker service.

# 启用docker
systemctl enable docker
# 启动docker服务
systemctl start docker

As shown below:

1.8. Stop and restart the docker service

Execute the following command to stop the docker service or restart the docker service.

# 停止docker
systemctl stop docker
# 重启docker
systemctl restart docker

At this point, the installation of the docker service on the Centos system is completed.

In summary, this article is over. It mainly introduces the installation of docker containers (Huawei Cloud HECS Yunyao Server) in Centos systems.

Guess you like

Origin blog.csdn.net/qq_39826207/article/details/134361936