Linux installation Docker complete tutorial

background

Recently, I took over several projects and found that the deployment of the projects is basically based on Docker. Fortunately, I was familiar with the basic use of Docker a few years ago, so I didn't get caught. With the development of cloud native in the past two years, Docker's role in cloud native has made it flourish.

Today's article will take you to realize the deployment process of Docker under the Linux operating system, and save it for emergencies. Of course, if you are interested in Docker, you can directly follow the steps in this article. One day you will enjoy the convenience and charm of Docker.

Docker and system version

Docker has been divided into CE (Community Edition: Community Edition) and EE (Enterprise Edition: Enterprise Edition) since version 17.03. Compared with the community version, the enterprise version emphasizes security, but needs to be paid for. Here we can use the community version.

Docker supports 64-bit versions of CentOS 7 and CentOS 8 and later, and it requires a Linux kernel version no lower than 3.10.

Check the Linux version of the command Here are two recommended: lsb_release -aor cat /etc/redhat-release.

lsb_release -aView the effect:

[ ~]$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.6.1810 (Core)
Release:	7.6.1810
Codename:	Core

cat /etc/redhat-releaseView version effect:

[~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

Obviously, the current Linux system is CentOS7. Then check whether the kernel version is not lower than 3.10.

There are three ways to check the kernel version:

  • cat /proc/version
  • uname -a
  • uname -r

The content version can be viewed in three forms, such as:

[ ~]$ uname -r
3.10.0-1160.45.1.el7.x86_64

It can be seen that the current Linux kernel version meets the requirements of Docker.

Docker automated installation

Docker official and domestic daocloud both provide one-click installation scripts, making Docker installation more convenient.

The official one-click installation method:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

Domestic daocloud one-key installation command:

curl -sSL https://get.daocloud.io/docker | sh

Execute any of the above commands and wait patiently to complete the Docker installation.

Docker manual installation

Manually install Docker in three steps: uninstall, set up warehouse, and install.

Uninstall Docker (optional)

The first step is to uninstall the historical version . This step is optional. If you have installed an old version of Docker before, you can use the following command to uninstall it:

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine \
                  docker-ce

Set source repository

The second step is to set up the warehouse . Before installing Docker Engine-Community for the first time on a new host, you need to set up a Docker repository. Afterwards Docker can be installed and updated from the repository.

Before setting up the repository, you need to install the required packages. yum-utils provides yum-config-manager, and the device mapper storage driver requires device-mapper-persistent-data and lvm2.

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

Execute the above command, and the warehouse can be set after the installation is complete. Use the official source address to set the command as follows:

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

Usually, the official source address is relatively slow, and the above source address can be replaced with a faster domestic address:

  • Alibaba Cloud : http : ** // mirrors.aliyun.com/docker-ce/linux/centos/**docker-ce.repo _
  • Tsinghua University source: https:**// mirrors.tuna.tsinghua.edu.cn / docker-ce / linux / centos /**docker-ce.repo

After the warehouse is set up, you can install Docker.

Docker installation

Execute the command to install the latest version of Docker Engine-Community and containerd.

sudo yum install -y docker-ce docker-ce-cli containerd.io

docker-ce is a free version for the community. Wait for a while, docker will be installed successfully. However, after the installation is complete, the default is not started, and it needs to be started.

If you do not need docker-ce-cli or containerd.io, you can directly execute the following command:

yum install -y docker-ce

At this point, the Docker installation is complete.

Docker start

Command to start Docker:

sudo systemctl start docker

Verify that Docker Engine-Community is installed correctly by running the hello-world image.

// 拉取镜像
sudo docker pull hello-world
// 执行hello-world
sudo docker run hello-world

If after execution, the console displays the following information, it means that Docker is successfully installed and started:

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

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

In addition to starting Docker, some other startup-related commands:

  • Daemon restart: systemctl daemon-reload
  • Restart the Docker service: systemctl restart docker / service docker restart
  • Close the Docker service: docker service docker stop / docker systemctl stop docker

remove docker

Remove the installation package:

yum remove docker-ce

Delete images, containers, configuration files, etc.:

rm -rf /var/lib/docker

Other common commands of Docker

After installing Docker, here is a summary of common Docker operation commands:

  • Search warehouse images: docker search image name
  • Pull image: docker pull image name
  • View running containers: docker ps
  • View all containers: docker ps -a
  • Delete container: docker rm container_id
  • View mirror: docker images
  • Delete image: docker rmi image_id
  • Start (stopped) container: docker start container ID
  • Stop the container: docker stop container ID
  • Restart the container: docker restart container ID
  • Start the (new) container: docker run -it ubuntu /bin/bash
  • Into the container: docker attach 容器IDor docker exec -it 容器ID /bin/bash, the latter is recommended.

More commands can docker helpbe viewed through commands.

summary

This article takes you through the installation of Docker on the Linux operating system from beginning to end, and introduces how to start, verify and common commands. If there is an organic conversation later, let's learn how to make a Docker image for CI/CD release.

Introduction to the blogger: The author of "SpringBoot Technology Insider" technical book, loves to study technology, and writes dry technical articles.

Public account: "Program New Vision", the blogger's public account, welcome to pay attention~

Technical exchange: Please contact the blogger WeChat ID: zhuan2quan


WeChat public account: a new vision of the program

" Program New Vision ", a public account with 100% technical dry goods

Guess you like

Origin blog.csdn.net/wo541075754/article/details/126026997