Install docker in Linux environment

1. Uninstall the old version

If you have installed docker engine before, then this step is necessary, please use the following command to delete the historical installation:

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

If the yum package manager replies that it is not installed, then this will not affect subsequent installations.
It should be noted here that when docker is uninstalled, the images, containers, volumes and networks stored in the /var/lib/docker/ directory will not be automatically deleted.

2. Selection of installation method

2.1. Setting up the repository

To install required packages and set up Docker's repository, use the following commands.

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

2.2. Install Docker engine

Install Docker engine, containerd and docker compose
To install the latest versions, run the following commands:

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

This command installs Docker, but does not start Docker. It also creates the Docker group, by default no users are added to this group.
This is often required if you need to install a specific version.
First you need to list the available versions in the repository, use the following command:

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

显示:
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

The returned list shows the version of the package. To install a specific version, you need to specify the package name plus the version string. Replace <VERSION_STRING> with the desired version, execute the following command:

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

2.3. Start docker

sudo systemctl start docker
We can verify that the installation was successful by running the image:

sudo docker run hello-world
This command will download the test image and run it in the container. When the container runs, it will print a confirmation message and exit.

Displayed as follows:

[root@localhost ~]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Guess you like

Origin blog.csdn.net/eettttttt/article/details/131820644