Image
 focus on
"The Script House
, with millions of developers

Image

Produced | Program New Horizon (ID: ershixiong_see_world)

Reprinted with the authorization of the original official account

background

I recently 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 catch it. With the development of cloud native in the past two years, Docker's role in cloud native has made it flourish.

Today, this article will take you to realize the deployment process of Docker under the Linux operating system, and collect 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 is 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 requires payment. Here we can use the community version.

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

Check out the Linux version of the command here to recommend two: lsb_release -aor cat /etc/redhat-release.

lsb_release -aCheck 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-releaseCheck out the version effect:

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

Obviously, the current Linux system is CentOS7. Check again 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 all three forms, such as:

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

As you can see, the current Linux kernel version meets the needs of Docker.

Automated installation of Docker

Both Docker official and domestic daocloud provide a one-click installation script, which makes the installation of Docker more convenient.

The official one-click installation method:

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

Domestic daocloud one-click 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

There are three steps to manually install Docker: uninstall, set up the repository, and install.

Uninstall Docker (optional)

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

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 up 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 the Docker repository. Docker can then be installed and updated from the repository.

Before setting up the repository, follow the required packages first. 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, you can replace the above source address with a faster domestic address:

  • Aliyun : 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 following 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. After a while, docker can be installed successfully. However, after the installation is completed, the default is not started, and a startup operation is required.

If you don't 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 the console displays the following information after execution, the Docker installation and startup are successful:

[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
  • Shut down 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

Docker other common commands

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

  • Search warehouse image: docker search image name
  • Pull the image: docker pull image name
  • View running containers: docker ps
  • View all containers: docker ps -a
  • Delete container: docker rm container_id
  • View image: docker images
  • Delete image: docker rmi image_id
  • Started (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 be viewed through the docker helpcommand.

summary

This article walks you through installing Docker on a Linux operating system, and describes how to start, verify, and common commands. If there is an organic conversation later, let's learn how to create a Docker image for CI/CD release.

<END>

Programmer exclusive T-shirt

Product direct purchase link👇 

Script house carefully selected , transaction guarantee , buy with confidence , programmer geek short-sleeved T-shirt

Image

  Recommended reading:

finally! I found the reason why programmers love to wear sweaters

The interns recruited by 7K, the mysterious past company behind Linux memory , don't know how to find files in Linux!

How to use the vmstat command under LinuxImage