Installing Docker engine on CentOS

To start using Docker Engine on CentOS, make sure   Preconditions met , then   Install Docker.

precondition

Operating system requirements

To install the Docker engine, you need a maintenance version of CentOS 7 or 8. Archive version is not supported or tested.

The CentOS extras library must be enabled. This repository is enabled by default, but if you have disabled it, you need to   Re enable it.

Overlay 2 recommends using a storage driver.

Uninstall old version

The old version of docker is called docker or docker engine. If these are installed, uninstall them and their associated dependencies.

<span style="color:#33444d"><span style="background-color:#ffffff"><span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum remove docker <span style="color:#cd5555">\</span>
                  docker-client <span style="color:#cd5555">\</span>
                  docker-client-latest <span style="color:#cd5555">\</span>
                  docker-common <span style="color:#cd5555">\</span>
                  docker-latest <span style="color:#cd5555">\</span>
                  docker-latest-logrotate <span style="color:#cd5555">\</span>
                  docker-logrotate <span style="color:#cd5555">\</span>
                  docker-engine
</code></span></span></span></span>

It doesn't matter if yum reports that these packages are not installed.

The contents of / var/lib/docker /, including images, containers, volumes, and networks, will be preserved. The Docker engine package is now called Docker CE

Installation method

You can install Docker Engine in different ways as needed:

  • Most users   Set the repository of Docker And install from it for installation and upgrade tasks. This is the recommended method.

  • Some users download RPM packages and   Manual installation And fully manually manage upgrades. This is useful in situations such as installing Docker on an air gap system that cannot access the Internet.

  • In the test and development environment, some users choose to use automated   Convenience script To install Docker.

Installing using a repository

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

Set up repository

Install the yum utils package (Yum config manager provided)   Utility) and set up a stable repository.

<span style="color:#33444d"><span style="background-color:#ffffff"><span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum install <span style="color:#8b008b">-y</span> yum-utils

<span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum-config-manager <span style="color:#cd5555">\</span>
    <span style="color:#8b008b">--add-repo</span> <span style="color:#cd5555">\</span>
    https://download.docker.com/linux/centos/docker-ce.repo
</code></span></span></span></span>

Optional: enable nighttime or test repository.

These repositories are included in the file above docker.repo, but are disabled by default. You can enable them next to stable repositories. The following command enables the nighttime repository.

<span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum-config-manager <span style="color:#8b008b">--enable</span> docker-ce-nightly
</code></span></span>

To enable the test channel, run the following command:

<span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum-config-manager <span style="color:#8b008b">--enable</span> docker-ce-test
</code></span></span>

You can disable or test the repository by running a command with flags  . To re enable it, use this flag. The following command disables the nighttime repository. yum-config-manager--disable--enable

<span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum-config-manager <span style="color:#8b008b">--disable</span> docker-ce-nightly
</code></span></span>

Learn about nightly and test channels.

Install Docker engine

  1. Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum install docker-ce docker-ce-cli containerd.io
    </code></span></span>

    If you are prompted to accept the GPG key, verify that the fingerprint matches 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35. If it matches  , Please accept.

    Multiple Docker repositories?

    If you have enabled multiple Docker repositories, click yum install or yum   Installing or updating without specifying a version in the yum update command always installs the highest possible version, which may not be suitable for your stability needs.

    This command installs docker, but does not start docker. It also creates a   Docker group, but by default it does not add any users to the group.

  2. To install a specific version of Docker Engine, list the available versions in repo, and then select and install:

    One. Lists and sorts the versions available in your repository. This example sorts the results by version number, from high to low, and is truncated:

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> yum list docker-ce <span style="color:#8b008b">--showduplicates</span> | sort <span style="color:#8b008b">-r</span>
    <span style="color:#888888">
    docker-ce.x86_64  3:18.09.1-3.el7                     docker-ce-stable
    docker-ce.x86_64  3:18.09.0-3.el7                     docker-ce-stable
    docker-ce.x86_64  18.06.1.ce-3.el7                    docker-ce-stable
    docker-ce.x86_64  18.06.0.ce-3.el7                    docker-ce-stable
    </span></code></span></span>

    The list returned depends on which repositories are enabled and is specific to your version of CentOS (. el7 in this example, it is represented by a suffix).

    bay   Install a specific version with a fully qualified package name, that is, the package name(   Docker CE) plus the colon from the first(  :) Start with the version string (column 2) until the first hyphen by the hyphen(  -) Separate. For example, docker-ce-18.09.1.

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
    </code></span></span>

    This command installs docker, but does not start docker. It also creates one   Docker group, but by default it does not add any users to the group.

  3. Start Docker.

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>systemctl start docker
    </code></span></span>
  4. By running Hello World   Verify that the Docker Engine is installed correctly using the image.

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>docker run hello-world
    </code></span></span>

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

This will install and run the Docker engine. Run the docking window command using sudo. Continue Linux postinstall To allow non privileged users to run Docker commands and other optional configuration steps.

Upgrade Docker engine

To upgrade Docker Engine, follow Follow the installation instructions , select the new version to install.

Install from package

If you cannot use Docker's repository to install Docker, you can download the. rpm version   File and install it manually. Each time you want to upgrade Docker Engine, you need to download a new file.

  1. go to Index of linux/centos/   And select your CentOS version. Then browse x86_64/stable/Packages/   And download the file of the Docker version to be installed.

    note

    To install a nightly or test (pre release) package, stable, change the word in the above URL to nightly or test.   Learn about nightly and test channels.

  2. Install Docker Engine and change the following path to the path where you download Docker package.

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum install /path/to/package.rpm
    </code></span></span>

    Docker was installed but not started. The docker group was created, but no users were added to the group.

  3. Start Docker.

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>systemctl start docker
    </code></span></span>
  4. By running Hello World   Verify that the Docker Engine is installed correctly using the image.

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>docker run hello-world
    </code></span></span>

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

This will install and run the Docker engine. Run the docking window command using sudo. Continue Post installation steps for Linux To allow non privileged users to run Docker commands and other optional configuration steps.

Upgrade Docker engine

To upgrade Docker Engine, download the updated package file and repeat   setup script , use yum -y upgrade   Replace yum -y install and point to the new file.

Install using convenience scripts

Docker is here get.docker.com   A convenient script is provided on to quickly and non interactively install Docker into the development environment. It is not recommended to use the convenient script in the production environment, but it can be used as an example to create a configuration script suitable for your needs. See also Installing using a repository   Step to learn about the installation steps of installing using the package repository. The source code of the script is open source and can be Docker install on GitHub of   Found in repository.

Before running locally, be sure to check scripts downloaded from the Internet. Familiarize yourself with the potential risks and limitations of convenience scripts before installing:

  • The script requires root or sudo privileges to run.
  • The script attempts to detect your Linux distribution and version and configure the package management system for you, and 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 current configuration of the host.
  • By default, the script installs the latest stable versions of Docker, containerd and runc. When configuring the machine with this script, the major version of Docker may be upgraded unexpectedly. Always test (Major) upgrades in a test environment before deploying to production systems.
  • This script is not intended to upgrade an existing Docker installation. When using scripts to update an existing installation, dependencies may not be updated to the expected version, resulting in an outdated version.

Tip: preview script steps before running

You can run with DRY_RUN=1 option to see the steps the script will perform during installation:

<span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> curl <span style="color:#8b008b">-fsSL</span> https://get.docker.com <span style="color:#8b008b">-o</span> get-docker.sh
<span style="color:#555555">$</span> <span style="color:#00688b">DRY_RUN</span>=1 sh ./get-docker.sh
</code></span></span>

This example is from get.docker.com Download script   And run it to install the latest stable version of Docker on Linux:

<span style="color:#33444d"><span style="background-color:#ffffff"><span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> curl <span style="color:#8b008b">-fsSL</span> https://get.docker.com <span style="color:#8b008b">-o</span> get-docker.sh
<span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>sh get-docker.sh
<span style="color:#888888">Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
</span><span style="color:#228b22"><...>
</span></code></span></span></span></span>

Docker is installed. The docker service starts automatically on Debian based distributions. On RPM distribution based distributions, such as CentOS, Fedora, RHEL, or SLES, you need to start it manually using the appropriate systemctlorservice command. As shown in the message, by default, non root users cannot run the docker command.

Use Docker as a non privileged user or install in rootless mode?

The installation script requires root or sudo to have permission to install and use Docker. If you want to grant non root users access to Docker, see   Post installation steps for Linux . Docker can also be installed without root privileges or configured to run in rootless mode. For instructions on running docker in rootless mode, see to   Run the Docker daemon as a non root user (rootless mode).

Install pre release

Docker is still there test.docker.com   A convenient script is provided on to install the pre release version of Docker on Linux. This script is equivalent to the script get.docker.com in, but it will configure your package manager to enable the "test" channel in our package repository, including the stable version and pre release version (beta version and candidate release version) of Docker. Use this script to access new versions in advance and evaluate them in the test environment before they are released stably.

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

<span style="color:#33444d"><span style="background-color:#ffffff"><span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> curl <span style="color:#8b008b">-fsSL</span> https://test.docker.com <span style="color:#8b008b">-o</span> test-docker.sh
<span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>sh test-docker.sh
<span style="color:#228b22"><...>
</span></code></span></span></span></span>

Upgrade Docker after using convenience script

If you install Docker using a convenience script, you should upgrade Docker directly using your package manager. There is no benefit in rerunning the convenience script, which can cause problems if it attempts to re add a repository that has been added to the host.

Uninstall Docker engine

  1. Uninstall Docker Engine, CLI, and container packages:

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>yum remove docker-ce docker-ce-cli containerd.io
    </code></span></span>
  2. Images, containers, volumes, or custom profiles on the host are not automatically deleted. Delete all mirrors, containers, and volumes:

    <span style="color:#0c5176 !important"><span style="background-color:#f5f8fa !important"><code><span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>rm <span style="color:#8b008b">-rf</span> /var/lib/docker
    <span style="color:#555555">$</span> <span style="color:#658b00">sudo </span>rm <span style="color:#8b008b">-rf</span> /var/lib/containerd
    </code></span></span>

You must manually delete any edited profiles.

Keywords: Operation & Maintenance CentOS Docker

Added by zoki on Wed, 22 Sep 2021 09:09:17 +0300