The latest Docker installation tutorial

foreword

To install Docker Engine on CentOS, a maintenance release of CentOS 7, CentOS 8(stream) or CentOS 9(stream) is required

This installation environment:

  • VMware 16.2.2
  • Linux system version:CentOS Linux release 7.9.2009 (Core)
  • For convenience, I rootinstalled it as a user. If you use a non- rootuser, some commands need to be addedsudo

Install

Enable centos-extras repository

It's on by default, but if you disabled it, you'll need to re-enable it

The specific method is as follows:

Check whether centos-extras is enabled

# yum repolist all

picture 7

The picture above shows that extrasit is not turned on

Enter the following command on the command line

# vim /etc/yum.repos.d/CentOS-Base.repo

The content is as follows

# ...省略其他内容
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=0

Set enabledthe value of1

# ...省略其他内容
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

Press keyesc , input :wqsave and exit

And enter the following command on the command line to clear the cache and create a new metadata cache

# yum clean all
# yum makecache

If there are problems that may occur during the process /var/run/yum.pid 已被锁定, you can ctrl+cexit first and try again later

Check again whether centos-extras is enabled

# yum repolist all

The display results are as follows:
picture 6

uninstall old version

If you have installed an old version before docker, you need to remove the previously installed dependencies first

Older versions of Dockerwere called dockerordocker-engine

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

/var/lib/docker/, including images, containers, volumes, and networks, will be preserved. The Docker Engine package is now called docker-ce

  1. docker-ce is an open source project maintained by docker company, and it is a free container product based on the moby project
  2. docker-ee is a closed-source product maintained by docker company and a commercial product of docker company

Installation method selection

docker-ceThere are many ways to install, such as manual installation by downloading rpmthe package, and 自动化脚本quick installation.

It is recommended to install through the used Dockerrepository. This installation method is also convenient for our future upgrades. This article also uses this installation method as an example.

rpmPackage address https://download.docker.com/linux/centos/
自动化脚本 address https://get.docker.com/

repository install docker

Docker EngineBefore installing for the first time on a new host , Dockerthe repository needs to be set up. After that, we can install and update from the repository Docker.

Set up the repository

Install yum-utilsthe package (which provides yum-config-managerthe program), then set up the repository

# yum install -y yum-utils
# yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

Install Docker Engine

Install the latest version Docker Engine, containerdand Docker Compose, if you want to install a specific version, you can go to the official website to view the installation process

# yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

The official documentation mentions:

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

But I didn't get this prompt when I installed it.

After the command is executed it installs Dockerbut does not start Docker.

It also creates a dockergroup , but by default it doesn't add any users to that group.

# cat /etc/group

picture 9

Start and verify Docker

# systemctl start docker

#此命令会下载测试镜像并在容器中运行它。当容器运行时,它会打印一条消息并退出
# docker run hello-world

The output is as follows:
picture 8

Uninstall Docker Engine

  1. Uninstall Docker Engine, CLI, Containerd and Docker Compose packages
# yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
  1. Images, containers, volumes, or custom configuration files on the host are not automatically deleted.

    Delete all images, containers and volumes:

# rm -rf /var/lib/docker
# rm -rf /var/lib/containerd

Any edited configuration files must be manually deleted

Configure Mirror Accelerator

Configure Alibaba Cloud Image Accelerator

https://cr.console.aliyun.com/cn-heyuan/instances/mirrors

picture 10

Add the operation document according to the above figure, and then restartdocker

# systemctl daemon-reload
# systemctl restart docker

Check whether the accelerator is configured successfully

# docker info

If there is the following content in the output information:

Registry Mirrors:
  https://[你配置的域名]/

Indicates that the configuration is successful

Summarize

At this point, Dockerthe relevant installation tutorials are over.

Reference link:

Official website installation tutorial

Guess you like

Origin blog.csdn.net/m0_52440465/article/details/127017304
Recommended