Docker learning one
What is Docker
Website: https://hub.docker.com/
docker
encapsulates and isolates processes, which is a virtualization technology at the operating system level
Since the isolated process is independent of the host and other isolated processes, it is also called a container
docker application scenario
- Automated testing and continuous integration, release
- Automated packaging and publishing of web applications
- Easy deployment of background applications
Advantages of
- Fast and consistent delivery of applications
- Portable and extensible
- Lightweight, fast, economical and efficient, squeezing
linux
own resources
What can Docker do?
Let me first talk about the difference between Docker and virtual machines
In the previous virtual machine, the system occupies a lot of resources, many steps are redundant, and the startup is still very slow, which is unbearable
Docker now looks like this,
The containers are isolated from each other and interfere with each other, and run together on the same operating system to maximize the use of operating system resources
the difference between Docker technology and virtual machine technology?
- Each container is isolated from each other, they have their own file system and will not affect each other
- The container does not have its own kernel or its own hardware. The application in the container runs directly in the kernel of the host machine.
- The traditional virtual machine is to virtualize a piece of hardware, run the completed operating system, and run applications on it
So what can Docker specifically do?
Do DevOps
There are several improvements in DevOps:
- Applications can be deployed and delivered faster
The troublesome installation steps in the past are gone forever, after using Docker containerization, package the image to release the test, one-click deployment and operation
- Can be upgraded and expanded more conveniently
Use Docker to package the project into a mirror, easy to upgrade and easy to expand
- Development, operation and maintenance, and testing will be easier
No longer have to worry about the inconsistency of the development environment, test environment, and operation and maintenance environment
- Use resources more efficiently
Dcoker runs in the kernel of the host, and multiple Docker instances can be deployed on this physical host
The composition of Docker
Docker uses a client-server (C/S) architecture model, using remote APIs to manage and create Docker containers
Three basic concepts of Docker:
The picture comes from the Internet
- Mirroring
It is equivalent to a root file system, similar to a template, which is static
- container
It is equivalent to an instance pulled from the template. The container is created by mirroring. We can create, start, stop, pause, delete, etc.
- storehouse
Used to save the image, it can be regarded as a code control center
Docker installation and use
Install
There are roughly the following ways to install Docker on the network:
- Automatic installation of official script
- Install using Docker repository
- Use ==shell== script installation
Let's take the ubuntu system as an example, and use the Docker warehouse to install. My ubuntu system version is as follows:
# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.5 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.5 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Set up warehouse
Install dependencies
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add Docker's official GPG key:
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
To verify the secret key, you can directly search for the 8 characters after 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
sudo apt-key fingerprint 0EBFCD88
The following output shows that the secret key is set correctly
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
Set up a stable version of the warehouse
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) \
stable"
Install Docker
Install the latest Docker version
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
After the installation is complete, verify that it is OK
You can check the version of docker docker version
# docker version
Client: Docker Engine - Community
Version: 20.10.7
API version: 1.41
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:56:40 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:48 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.8
GitCommit: 7eba5930496d9bbe375fdf71603e610ad737d2b2
runc:
Version: 1.0.0
GitCommit: v1.0.0-0-g84113ee
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Run a hello-world
sudo docker run hello-world
The following message appears, indicating that the docker installation is successful
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Status: Downloaded newer image for hello-world:latest
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/
Of course, you can also choose not to install the latest version, or you can install the version you specify
- Use ==apt-cache madison docker-ce== to view the versions available in the warehouse
- Use ==sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io== install the specified version of Docker
- Use ==sudo docker run hello-world== to verify that the installation is successful
- View docker image
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
- docker image
卸载镜像
sudo apt-get purge docker-ce docker-ce-cli containerd.io
删除安装目录
/var/lib/docker 是docker 的默认安装路径
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
Mirror acceleration
If you are a small partner using Alibaba Cloud server, you can see this step
To configure image acceleration, the installation version of docker needs to be above 1.10.0, and the version of docker we currently install is 1.41, which is fully in line with
We can use the accelerator by modifying the daemon configuration file /etc/docker/daemon.json
, execute the following instructions
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://uhr5ub75.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
The process of docker run
- docker run Now find the corresponding mirror locally, and run it directly if there is one
- If not, go to the docker hub to download, if there is, download to the local and run
- If not, report an error directly
The underlying principle of Docker
How does Docker work?
Docker is a C/S model. The background guard of docker runs on the host, and the client and server communicate through sockets.
When the docker server receives an instruction from the docker client, it executes the instruction
Why is Docker faster than virtual machines?
I found a picture on the Internet, let’s compare it and it’s clear
As shown in the figure, the reasons why Docker is faster than virtual machines are as follows:
- Docker has fewer abstraction layers than virtual machines
- Docker uses the kernel of the host machine, and the virtual machine needs to create a new OS
Based on the above 2 points, when the virtual machine starts, it will load the operating system, the startup is slow, and the time is basically minutes.
When docker starts, there is no need to load the operating system kernel, so it is fast, and the time is basically seconds
Reference materials:
Welcome to like, follow, favorite
Friends, your support and encouragement are my motivation to keep sharing and improve quality
Okay, that's it for this time
Technology is open, and our mindset should be more open. Embrace the change, live toward the sun, and work hard to move forward.
I am little magic boy , welcome to like and follow the collection, see you next time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。