Docker learning 1
What is Docker
website: hub.docker.com/
docker encapsulates and isolates processes, which belongs to virtualization technology at the operating system level
Because 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
- Automatic packaging and publishing of Web applications
- Easy deployment of background applications
Advantages of docker
- Deliver applications quickly and consistently
- Portable and extensible
- Lightweight, fast, economical and efficient, squeezing linux's own resources
What can Docker do?
Let's talk about the difference between Docker and virtual machine
The previous virtual machine system takes up a lot of resources, many steps are redundant, and the startup is too slow to bear
Now Docker is like this,
Containers are isolated from each other, complementary interference, run together on the same operating system, and maximize the use of operating system resources
What is 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 and hardware. The applications in the container run directly in the kernel of the host
- The traditional virtual machine is to create a virtual hardware, run the completed operating system, and run applications on it
So what can Docker do?
Do DevOps
DevOps has the following advantages:
- Applications can be deployed and delivered more quickly
The previous troublesome installation steps are gone forever. After using Docker container, package the image, release the test, and deploy and run with one click
- It can be upgraded and expanded more conveniently
Using Docker, the project is packaged into an image, which is convenient for upgrading and capacity expansion
- Development, operation and maintenance and testing will be simpler
There is no need to worry about the inconsistency of development environment, test environment and operation and maintenance environment
- More efficient use of resources
Dcoker runs in the kernel of the host, and multiple Docker instances can be deployed on this physical host
Composition of Docker
Docker uses client server (C/S) architecture mode and remote API s to manage and create docker containers
Three basic concepts of Docker:
Pictures from the Internet
- image
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 through image. We can create, start, stop, pause and delete it
- Warehouse
The used to save images can be regarded as a code control center
Installation and use of Docker
install
There are several ways to install Docker on the network:
- Automatic installation of official scripts
- Install using Docker warehouse
- Install using = = shell = = Script
Let's take the ubuntu system as an example and install it in the Docker warehouse. The version of my ubuntu system 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 dependent packages
sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
Add the official GPG key of Docker:
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 the 8 characters after 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
sudo apt-key fingerprint 0EBFCD88
The following output sets the secret key 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 stable version 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 installation, verify that it is OK
You can view the docker version through 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. The installation of docker 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 choose not to install the latest version, or you can install your own specified version
Use = = apt cache Madison docker CE = = to view the versions available in the warehouse
Use = = sudo apt get install Docker CE = Docker CE cli = containerd. IO = = install the specified version of Docker
Use = = sudo docker run Hello world = = to verify that the installation was successful
- View docker image
# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d1165f221234 4 months ago 13.3kB
- docker image
Unmount mirror sudo apt-get purge docker-ce docker-ce-cli containerd.io Delete installation directory /var/lib/docker yes docker Default installation path for sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd
Image acceleration
If you are a small partner using alicloud server, you can see this step
To configure image acceleration, the installed version of docker needs to be above 1.10.0. The currently installed version of docker is 1.41, which fully conforms to
We can use the accelerator by modifying the daemon configuration file / etc/docker/daemon.json, and 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
Process of docker run
- docker run now finds the corresponding image locally and runs it directly if any
- If not, go to the docker hub to download it. If yes, download it locally and run it
- If not, report the error directly
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 Socket
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 map on the Internet and let's compare it
As shown in the figure, the reasons why Docker is faster than virtual machine are as follows:
- docker has fewer abstraction layers than virtual machines
- docker uses the kernel of the host, while the virtual machine needs to create an OS
Based on the above two points, the operating system will be loaded when the virtual machine is started, which is slow, and the time is basically minute
When docker starts, there is no need to load the operating system kernel, so it is fast and the time is basically seconds
reference material:
Welcome to like, follow and collect
My friends, your support and encouragement are the driving force for me to insist on sharing and improve quality
Well, that's all for this time
Technology is open, and our mentality should be open. Embrace change, live in the sun and strive to move forward.
I'm Nezha, the Little Devil boy. Welcome to praise and pay attention to the collection. See you next time~