Install docker install docker on centos

1. Operating system requirements

To install  Docker Engine , you need  a maintenance release of one of the following CentOS releases:

  • CentOS 7
  • CentOS 8 (stream)
  • CentOS 9 (stream)

Archived versions are not supported or tested.

The centos-extras  repository must be enabled . This library is enabled by default, but if you disabled it, you will need to  re-enable it .

overlay2  recommends using a storage driver .

2. Uninstall the old version

Older versions of Docker were named docker or docker-engine . Uninstall any such older versions, and associated dependencies, before attempting to install a newer version:

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

If yum reports that those packages are not installed, that's fine too.

When you uninstall Docker , images, containers, volumes, and networks stored in /var/lib/docker/ are not automatically removed.

3. Installation method

You can install Docker Engine in different ways depending on your needs:

  1. You can  set up Docker's repository and install from it to simplify installation and upgrade tasks ( recommended ).
  2. You can download RPM packages and  install them manually and manage upgrades entirely manually. This is useful in situations such as installing Docker on an air-gapped system without internet access.
  3. In test and development environments, you can use automated  convenience scripts to install Docker.

3.1 Install using warehouse

Before installing Docker Engine on a new host for the first time, you need to set up a Docker repository. After that, you can install and update Docker from the repository.

Tips: The installation process needs to wait for a while, and enter y when the command appears to choose whether to continue.

3.1.1 Setting up warehouse

Install the yum-utils package (provides the yum-config-manager  utility) and set up the repository.

Official website installation command:

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

Replenish: 

yum-utils provides yum-config-manager, device-mapper-persistent-data and lvm2 provide device mapper storage driver.

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

Using the official address will be slower, and it is recommended to use a domestic address.

Ali Cloud

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

Source from Tsinghua University

sudo yum-config-manager \
    --add-repo \
    https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

3.1.2 Install Docker Engine-Community

1. Install the latest version of Docker Engine-Community and containerd

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

2. If you need to install a specific version of Docker Engine-Community, you need to list the available versions first, and select a specific version to install

yum list docker-ce --showduplicates | sort -r

The list returned depends on which repositories are enabled and is specific to your CentOS release ( .el7denoted by the suffix in this example).

Install a specific version by its fully qualified package name, which is the package name (  docker-ce) plus the version string (column 2), starting with the first colon (  :) and ending with the first hyphen,  -separated by hyphens ( ). For example, docker-ce-17.09.1.

Substitute <VERSION_STRING>the desired version, then run the following command to install:

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin

3. After executing the installation command, the Docker installation is completed, but Docker will not be started. It creates a  dockergroup to which no users are added by default.

3.1.3 Upgrade version

To upgrade the Docker engine, follow 3.1 Installing from a repository, selecting the new version to install.

3.2 RPM package installation

If you cannot install Docker using Docker's repository, you can download  .rpmthe file for your version and install it manually. Every time Docker Engine is upgraded, a new file needs to be downloaded.

3.2.1 Download offline package

Go to https://download.docker.com/linux/centos/ and choose your CentOS version. Then browse x86_64/stable/Packages/ and download the .rpm file for the version of Docker you want to install.

3.2.2 Install Docker Engine

Change the path below to the path where you downloaded the Docker package.

sudo yum install /laq/rpm/docker-version.rpm

After executing the command, Docker is installed but not started. The dockergroup was created, but no users were added to the group.

3.2.3 Upgrade version

To upgrade the Docker engine, download the updated package file and repeat the process of installing the 3.2RPM package, using yum -y upgrade instead of yum -y install, and pointing to the new file.

3.3 Script installation

Tips: It is recommended to use the installation methods of 3.1 and 3.2.

Docker provides a handy script at https://get.docker.com/ for non-interactively installing Docker into a development environment. The convenience script is not recommended for production environments, but it can be useful for creating provisioning scripts tailored to your needs. See also  Installation steps using a repository for installation steps for installing using a package repository. The source code for this script is open source and you can  find it in the docker-install repository on GitHub .

Always check scripts downloaded from the Internet before running them locally. Before installing, familiarize yourself with the potential risks and limitations of the convenience script:

  • The script requires root or sudo privileges to run.
  • The script attempts to detect your Linux distribution and version, and configures the package management system for you.
  • The script does not allow you to customize most installation parameters.
  • The script installs dependencies and recommendations without confirmation. This may install a large number of packages, depending on the host's current configuration.
  • By default, the script installs the latest stable versions of Docker, containerd and runc. When using this script to provision a machine, it may cause unexpected major version upgrades of Docker. Always test upgrades in a test environment before deploying to your production systems.
  • This script is not designed to upgrade existing Docker installations. When using scripts to update an existing installation, dependencies may not be updated to the expected versions, resulting in outdated versions.

Tips: Preview script steps before running You can run a script with the option --dry-run to see which steps the script will run when invoked:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run

 This example downloads the script from https://get.docker.com/ and runs it to install the latest stable version of Docker on Linux:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

You have now successfully installed and started the Docker engine. The docker service starts automatically on Debian based distributions. On base distributions like RPMCentOS, Fedora, RHEL or SLES, you need to start it manually using the appropriate systemctl or service command. As the message indicates, non-root users cannot run Docker commands by default. 

Docker also provides a script at https://test.docker.com/ for installing pre-release versions of Docker on Linux. This script is equivalent to the script in get.docker.com, but configures your package manager to use the test channel of the Docker package repository. The test channel includes stable and pre-release versions (beta, release candidates) of Docker. Use this script to get early access to new releases and evaluate them in a test environment before they are released as stable releases.

To install the latest version of Docker on Linux from the test channel, run:

curl -fsSL https://test.docker.com -o test-docker.sh
sudo sh test-docker.sh

updated version

If you installed Docker using the convenience script, you should upgrade Docker directly using your package manager. There is no benefit to re-running the convenience script. Re-running it may cause problems if it tries to reinstall repositories that already exist on the host. 

4. Start docker

sudo systemctl start docker

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

5. Verify docker

Docker has a built-in mirror hello-word, which can be used to verify whether Docker Engine-Community is installed correctly.

sudo docker run hello-world

6. Uninstall the Docker engine

6.1 Uninstall the package

Docker Engine, CLI, containerd and Docker Compose packages

sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

6.2 Delete all images, containers and volumes

Images, containers, volumes or custom configuration files on the host are not automatically deleted.

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

Official website: Install Docker Engine on CentOS | Docker Documentation

Guess you like

Origin blog.csdn.net/qq_57226198/article/details/130188387