Section 10: Getting started with Docker + download, install and configure

1. Project deployment issues

There are many components in large-scale projects, and the operating environment is also relatively complex. Some problems will be encountered during deployment:

1. When each application is deployed on a Linux server, it needs some preparatory work, because it needs to install its own dependencies and function libraries. Different applications may have different dependencies or different versions, which leads to complicated relationships and compatibility issues.

2. There are differences in different environments, development, testing, and production environments. For example, different environments have different operating systems, or different versions.

The deployment of the project is particularly time-consuming.

Screenshot 2022-04-09 4.41.32 pm

2. Getting to know Docker first

2.1, for different dependencies

Docker packages the application's Libs (function library), Deps (dependency), configuration, and application together, and puts each application in an isolated container to run to avoid mutual interference.

Screenshot 2022-04-09 4.41.59 pm

2.2. For different systems

The computer kernel interacts with the computer hardware and provides instructions to operate the hardware. The system encapsulates the kernel instructions into functions, which are convenient for programmers to call.

So different systems have different functions.

Screenshot 2022-04-09 4.44.56 pm

Therefore, Docker will package the system function library and application dependencies together, so that even if it is placed in a different operating system, as long as it is the Linux kernel, it can run.

2.3. Summary

How does Docker solve the compatibility problems of complex dependencies and dependencies of different components in large-scale projects?

  • Docker allows applications, dependencies, function libraries, and configurations to be packaged together during development to form a portable image
  • Docker applications run in containers and use the sandbox mechanism to isolate them from each other

How does Docker solve the problem of differences in development, testing, and production environments?

  • The Docker image contains a complete operating environment, including system function libraries, and only depends on the Linux kernel of the system, so it can run on any Linux operating system

3. Docker and virtual machines

A virtual machine (virtual machine) simulates a hardware device in an operating system, and then runs another operating system, such as running an Ubuntu system in a Windows system, so that any Ubuntu application can be run.

In this way, the application will first call the system installed in the virtual machine, then call the Windows operating system, and then call the hardware.

Docker only packages the required dependencies, function libraries, etc. During the running of the application, it directly calls the hardware through the operating system.

characteristic Docker virtual machine
performance close to native poor performance
hard disk usage Usually MB Generally GB
start up second level minute level

Differences between Docker and virtual machines:

1. docker is a system process; the virtual machine is the operating system in the operating system

2. docker is small in size, fast in startup speed and good in performance; the virtual machine is large in size, slow in startup speed and average in performance

4. Docker architecture

4.1. Images and containers

Image : Docker packages applications and their required dependencies, function libraries, environments, configurations, and other files together, called images.

Container (Container): The process formed after the application in the image runs is a container, but Docker will isolate the container and make it invisible to the outside world.

Containers are isolated from each other. Mirroring is read-only, such as Mysql database mirroring. After running, if it can be written to the mirroring, the mirroring will be modified, so the mirroring is read-only. The container will make a copy of the file in the image for writing.

4.2. Docker and DockerHub

DockerHub: DockerHub is a hosting platform for Docker images. Such a platform is called a Docker Registry.

There are also public services similar to DockerHub in China, such as NetEase Cloud Mirror Service, Alibaba Cloud Mirror Library, etc.

4.3. docker architecture

Docker is a program of CS architecture, which consists of two parts:

1. Server (server): Docker daemon process, responsible for processing Docker instructions, managing images, containers, etc.

2. Client (client): Send instructions to the Docker server through commands or RestAPI. Commands can be sent to the server locally or remotely.

Screenshot 2022-04-09 5.06.27 pm

The client can send commands to the server

When the dockerbuild command reaches the server, it will be received and processed by the server daemon, and the image will be built through the parameters you provide.

The docker pull command can go to the remote Registry to pull the image to the server.

docker run will use the image to create a container.

5. Install Docker

5.1, version

Docker is divided into two major versions, CE and EE. CE stands for Community Edition (free of charge, with a support period of 7 months), and EE stands for Enterprise Edition, which emphasizes security and is paid for, with a support period of 24 months.

Docker CE is divided stable testinto nightlythree update channels and .

There are installation . Here we mainly introduce the installation of Docker CE on Ubuntu.

5.2. System requirements

One of the following systems needs to be 64-bit

  • Free Impish 21.10
  • Free Hirsute 21.04
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)

my system:Screenshot 2022-04-09 5.22.36 pm

5.2. Uninstall the old version

sudo apt-get remove docker docker-engine docker.io containerd runc

5.3. Download from remote warehouse

1. Update the apt package index and install the package to allow apt to download from the remote repository via HTTPS:

 sudo apt-get update
 sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

2. Add docker GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

3. Use the following command to set up a stable repository. To add a nightly or test repository, add the word nightly or test (or both) after the word stable in the command below.

Docker Engine has three types of update channels: stable, nightly and test:

  • The Stable channel provides you with the latest releases for full use.

  • test provides pre-releases that are ready for testing before general release (GA).

  • nightly gives you the latest version for the next major release.

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

4. Download Docker

Download the latest version directly:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Download the specified version:

List versions:

apt-cache madison docker-ce 

Screenshot 2022-04-09 5.40.05 pm

Select the specified version to download:

 sudo apt-get install docker-ce=5:20.10.14~3-0~ubuntu-focal docker-ce-cli=5:20.10.14~3-0~ubuntu-focal containerd.io

5. Check whether it is successful

sudo docker run hello-world

Screenshot 2022-04-09 5.44.09 pm

5.4. Related commands

service docker status

Active (running) indicates successful startup

Screenshot 2022-04-09 5.48.24 pm

service docker start #启动
service docker stop  #关闭
service docker restart#重启

5.5. Mirror acceleration

The network speed of docker's official mirror warehouse is poor, so we need to set up a domestic mirror service:

Refer to Alibaba Cloud's mirror acceleration document: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

Modify the /etc/docker/daemon.json configuration file

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://9yux2oo3.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

5.6. Uninstall Docker

sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

Guess you like

Origin blog.csdn.net/LookOutThe/article/details/124065100