Recently, the company adjusted the micro service architecture , I'm lucky to be in touch with Docker, Just beginning to come into contact with docker When I went to Baidu, I went to Baidu docker Containers , come to know docker Belong to linux One of the containers , adopt docker,linux Containers have developed into an excellent tool . Today, what we have learned about Docker A brief summary of the application of , At the same time, I hope I can help you .
- Virtualization technology
- Why use virtualization technology
Virtualization technology can make sense 、 Efficient use of resources 、 Cost savings . For example, in the double 11 Shopping Festival , Tmall 、 TaoBao 、 The business of Jingdong and other major shopping websites has increased dramatically , Correspondingly, the demand for back-end servers supporting these businesses will also increase significantly , And in the off-season , There will be a lot less business , Accordingly, the server pressure will be reduced . In order not to waste resources , Using virtualization technology can achieve the purpose of dynamic and reasonable allocation of resources .
- Traditional virtualization technology ( Host level virtualization )
Traditionally, virtualization technology is divided into two types ： One is in the hardware device layer ( The host machine ) Direct simulation on the Internet , To achieve multiple operating systems ; One is running on the host VMware, And then in VMware It's running the client , The client then calls the underlying device , such as CPU, Memory , Disk and other hardware resources .
- System level virtualization technology ( Container level virtualization technology )
Container level virtualization has no host , And there's no virtual machine manager , Shared kernel between virtual machines and virtual machines , No need to simulate hardware layer , At the same time, on the kernel of the operating system , Allow multiple isolated user spaces . This is similar to Xiao Ming's one day when he wanted to eat potato chips at the same time , French fries and meatballs , What shall I do? ？ One way is for him to buy 3 A pot of the same size , At the same time , But it's obvious that this method will cause a waste of resources , Another way is to buy a mouthful with 2 It's a big pot with compartments , And the area of each partition layer is different , In this way, you can fry your favorite chips according to your preference , French fries and meatballs , Eat more on the larger area of the partition , Eat less on the smaller area of the partition , It's not a waste of resources , And make the best use of space .
- Container Core technologies
CGroup： Limit the use of resources , For example, how many CPU, How much memory does it take .
NameSpace： An optional parameter is added to create a new process PID, And then use it Linux system call The clone method specifies a new PID Parameters , Then the newly created process will see a new process space , Which is the corresponding PID Parameters .Namespace In addition to being able to simulate PID outside , It also provides Mout、UTS、IPC、Network and User etc. , Do isolation operations in different process contexts .
Chroot： Isolate the file system
- Docker Introduce
- What is a container ？
A water cup is a container for holding water , A fruit basket is a container for fruit , Empathy ,Docker It's a container for applications , Like something we're familiar with MySQL,Nginx etc. .
- What is? Docker？
Docker It's used to create 、 Deploy 、 Tools to run applications , For example, the current popular micro Services ,CI/CD.
- Why use Docker？
Docker Containers are completely sandboxed using the sandbox mechanism , There will be no interface between them （ similar iPhone Of app）, More importantly, the container performance overhead is minimal . Because of the advantages of this technology ,Docker Developing 、 test 、 Operation and maintenance are widely used . In the field of development , Will use Docker Build development environment ; In the field of testing , Will use Docker Set up the test environment , For example, the Zen system that manages test cases , For multi version testing , Corresponding to multiple test environments , If you use Docker, You can enable different Docker We can achieve our goal ; In the field of operations and maintenance , Allocate network resources , Build a monitoring system , Backup system can be used Docker.
- install Docker
Install... On different operating systems Docker The method is different , You can use your own operating system to search for the installation method .
- Docker Basic operation
- Docker image
List the mirror ：docker images
Download mirroring ：docker pull
delete mirror ：docker rmi Image name
View image details ：docker ps -a
- Docker Container
Run container ：docker run -it
List containers ：docker container ls
View the process and resource utilization of the container ：docker ps -a
stop it / Open the container ：docker start/stop < Containers ID>
Delete container ：docker rm -f < Containers ID>
- Docker Application scenarios
- Rapid deployment
Using virtualization technology , The replacement of hardware resources takes a few days , Virtualization technology reduces this time to a few minutes , Since the introduction Docker technology , This operation can be controlled in a few seconds .
- Simplified configuration
The biggest advantage of virtual machine is that it can run different operating systems on the same host , and Docker You can put the runtime environment and configuration in your code and run , Relevancy between degraded hardware and application environment .
- Isolate applications and integrate services
because Docker The application has no host , And there's no virtual machine manager , Shared kernel between virtual machines and virtual machines , No need to simulate hardware layer , At the same time, on the kernel of the operating system , Allow multiple isolated user spaces , This ability to isolate applications makes docker Multiple services can be integrated to reduce costs .
Of course Docker There are many more application scenarios , For example, multi tenant environment , Debugging ability, etc , I won't introduce them here . I can reach you today Docker, It also depends on 《Linux It's time to learn 》 This book , It was it that brought me into contact with virtualization technology , This book is easy to understand , It's great for getting started , Students in need can check it by themselves .