Docker
Docker summary
Docker It's a kind of Containerization Technology , Used to isolate boundary problems between applications .Docker The two most common concepts are : Mirror image (Image)、 Containers (Container).
Mirror image (Image)
Mirror image (Image) Is all the file resources used by the current program running . It can be simply understood as Mirror image (Image) It contains all the file resources needed for the program to run ( File resources including system programs ).
For example, a front-end application image , Need to rely on Nginx The server , Nginx Dependent systems .
Therefore, a front-end application image contains the operating system file resources 、Nginx File resources .
So mirroring can be done at will “ Carry ” , Not affected by the host environment ( The local system ) influence .
Mirror image (Image) The design scheme is designed in layers , A large number of basic images are provided in the community , You can use these basic images to build images .
For example, front-end application mirroring , Use it directly Nginx Mirror build mirror , It's equivalent to Nginx Another layer is added to the mirror layer . and Nginx Mirror image is also in System image layer A layer added to .
Layering brings many benefits .
PS:
DockerNot completely unaffected by the system environment ,DockerThe container is running on the host environment , Isolation at the software level , Instead of the direct isolation of virtual machines on hardware
PS:
Mirror image (Image)The hierarchy is actually more elaborate . stay Dockerfile In file , A statement is a layer .
Containers (Container)
Containers (Container) It's based on Mirror image (Image) A process created in the system , It's just some special treatment for this process . for example : Isolation limit (Namespace) and Resource constraints (Control Group)
It can be simply understood as Containers (Container) It's a restricted process .
Docker and Containerization There are many things in it , If you are interested, you can learn by yourself
Docker Deploy
HTTPS Tools
Docker Installation needs HTTPS Protocol installation , Generally, the first step is to install apt-transport-https
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Tencent cloud server already has HTTPS Package of agreement , So omit this step directly , If not, use the above statement to install

add to Docker Repository key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add to Docker The repository apt Source
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
[arch=amd64]Expressamd64framework , Others havearmhf、arm64And so on$(lsb_release -cs) stableStable version . alsoedge( Experience )、test( test )
apt After the source is added successfully, it can be added in /etc/apt/sources.list The file to view

And then update apt The configuration file
sudo apt update
install Docker CE
Docker Version is divided into Docker EE( Enterprise Edition ) and Docker CE( Community Edition ).Docker EE Provides some advanced features for charging .
have access to apt View the currently available Docker CE edition
apt list -a docker-ce

In the latest version at the time of writing this article Docker-CE 20.10.12, Install... Here Docker-CE 20.10.12
sudo apt install docker-ce=5:20.10.123-0ubuntu-focal
After successful installation, you can cancel Docker Automatic update of , Prevent version updates from causing errors .
sudo apt-mark hold docker-ce
Docker Startup and setup
start-up Docker service
service docker start
After successful startup, you can execute Docker command

Add users to Docker Group
In Africa root User execution Docker The command must use sudo, It's a tedious process , You can add a specified user to Docker The group solves this problem

Add users to Docker Group
sudo usermod -aG docker [USER]
After adding, you need to log in again to take effect

Set up Docker Mirror source
Docker The default image source address is abroad , Image pulling will be slow , You can change the image source to a domestic image source
modify Docker The default source is modification /etc/docker/daemon.json( There is no such document , You can create it yourself )
Add a domestic image to this file , You can add one or more .
Added here Netease image source 、 Mirror source of China University of science and Technology 、Docker Official China mirror source
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}

After adding, you need to restart Docker service
sudo systemctl daemon-reload
sudo systemctl restart docker
After successful restart, you can use docker info Command to view the result of modification

among Registry Mirrors Is the image source attribute .
Docker Compose
Docker Compose summary
Docker Compose It's a Docker Layout tools ( Container group management ). It can be for many Containers Merge into one group for management .
In the real world , A project often has multiple applications , A project may consist of multiple containers , That is to form a container group .Docker Compose Is to provide management tools for this group .
PS: A container is an atomic unit , Although multiple applications can be directly ( Multiple processes ) Packed in a container , But this is not recommended , The container should keep single process execution
Docker Compose Used YAML Markup language as configuration file , So use Docker Compose management Containers Another advantage is to organize container configurations in a file form , Not just the command line
Container choreography tools and other tools , Like the famous kubernetes(k8s), also Docker SWARM、K3s etc. .
At the enterprise level, they usually use kubernetes(k8s), But I'm still small 4G Forget about the server .
At first I wanted to choose K3s, But the deployment of that thing is also a little troublesome , It takes up a lot of resources , After thinking about it, there is no need to use the cluster scheme for a single machine , Finally, I directly chose Docker Compose.
Docker Compose Deploy
Docker Compose The installation package can be directly from github download , The latest version is v2.2.3.

It can be used directly in the server curl download
sudo curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
But domestic visits github It's really super slow , Therefore, it is recommended to download directly locally ( Using accelerators ), Then upload the server
Pay attention to the system version when downloading , In general, it's Linux x86_64, If you don't trust, you can use uname -sm Command view

After the local download is complete , Rename the file to docker-compose And upload it to the server /usr/local/bin/ Directory is equivalent to successful installation .
PS: When uploading, please pay attention to the user who logs in , General users do not have permission to upload this directory , All my upload operations are done using
rootuser .

After installation , The average user does not perform Docker Compose Authority , Need to set up Docker Compose Read and write permission of .
sudo chmod +x /usr/local/bin/docker-compose
Here directly Docker Compose The execution permission of is set to all users , If you need detailed settings , Use chmod Command specific parameter settings
After setting, you can execute docker-compose The command

Docker Compose command
docker-compose Command to view online information , I'm not familiar with specific orders , They all use online cash check , Generally, another management tool is also used Portainer To execute .
![[source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit](/img/3e/ab14f3a0ddf31c7176629d891e44b4.png)





![[uc/os-iii] chapter 1.2.3.4 understanding RTOS](/img/33/1d94583a834060cc31cab36db09d6e.jpg)


