Analysis of Linux container -- docker

linuxprobe2020 2021-04-08 09:11:24
analysis linux container docker

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
  1. 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 .

  1. 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 .

  1. 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 .

  1. 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 MoutUTSIPCNetwork and User etc. , Do isolation operations in different process contexts .

Chroot: Isolate the file system


  • Docker Introduce
  1. 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. .

  1. What is? Docker

Docker It's used to create 、 Deploy 、 Tools to run applications , For example, the current popular micro Services ,CI/CD.

  1. 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
  1. Docker image

List the mirror :docker images

Download mirroring :docker pull

delete mirror :docker rmi Image name

View image details :docker ps -a

  1. 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
  1. 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 .

  1. 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 .

  1. 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 .


  1. Spring Boot 中如何统一 API 接口响应格式?
  2. 深入分析 SpringMVC 参数解析器
  3. SpringBoot 中如何自定义参数解析器?
  4. SpringMVC 初始化流程分析
  5. 如何优雅的实现 Spring Boot 接口参数加密解密?
  6. Spring5 里边的新玩法!这种 URL 请求让我涨见识了!
  7. SpringMVC 中的参数还能这么传递?涨姿势了!
  8. 手把手教你开发 MyBatis 插件
  9. 细品 Spring Boot+Thymeleaf,还有这么多好玩的细节!
  10. Spring Boot 日志各种使用姿势,是时候捋清楚了!
  11. Deep analysis of viewresolver of nine components of spring MVC
  12. In depth analysis of handleradapter of nine components of spring MVC
  13. In depth analysis of handlermapping of nine components of spring MVC
  14. Can spring boot define interface methods to be declared private?
  15. Dispatcherservlet of spring MVC source code analysis
  16. Framework servlet for spring MVC source code analysis
  17. How to unify API response format in spring boot?
  18. In depth analysis of spring MVC parameter parser
  19. How to customize parameter parser in springboot?
  20. Analysis of spring MVC initialization process
  21. How to realize encryption and decryption of spring boot interface parameters gracefully?
  22. A new way to play in spring 5! This kind of URL request makes me see better!
  23. Can parameters in spring MVC be passed like this? It's up!
  24. Hand in hand to teach you how to develop mybatis plug-ins
  25. Fine spring boot + thymeleaf, there are so many fun details!
  26. Spring boot logs all kinds of posture, it's time to clear!
  27. Web 3.0踏浪而来,分布式存储举足轻重|时空云邀请您参加Web3.0中国峰会暨分布式存储行业大会
  28. spring-aop 进不了切面方法的解决办法
  29. Web 3.0 is coming, distributed storage is very important | spatiotemporal cloud invites you to attend Web3.0 China Summit and distributed storage industry conference
  30. The solution of spring AOP can't enter the section method
  31. Linux中如何启用root用户
  32. How to enable root in Linux
  33. 踩坑 MySQL 索引,看看你真的会用吗?
  34. Hive优化之配置参数的优化(一)
  35. Step on the MySQL index to see if you really know how to use it?
  36. Optimization of configuration parameters for hive optimization (1)
  37. Linux入门教程资料分享
  38. Introduction to Linux
  39. 外部连接mysql docker容器异常
  40. Exception of external connection MySQL docker container
  41. Zookeeper分布式锁?
  42. Zookeeper distributed lock?
  43. 嵌入式Linux_Framebuffer_03点阵显示ASCII字符串
  44. 嵌入式Linux_Framebuffer_02字符编码
  45. Embedded Linux_ Framebuffer_ 03 dot matrix display ascii string
  46. Embedded Linux_ Framebuffer_ 02 character encoding
  47. Looking forward to new product launch of Xiaomi in spring CNMO takes you to see 11 new products in advance
  48. An inventory of the commonly used garbage collectors in Java
  49. Why is it so easy to get started with HBase?
  50. Implementation of PRC framework based on netty
  51. 2021 Java back end engineer must know knowledge - (Dubbo, distributed RPC framework)
  52. 关于spring advisor和元数据 同时来管理事务的问题
  53. How to manage transactions with spring advisor and metadata at the same time
  54. 使用Playwright对Java API实现自动视觉测试 - applitools
  55. Using playwright to implement automatic visual testing for Java API - applitools
  56. Dubbo和Spring cloud、Istio对比图
  57. Comparison of Dubbo with spring cloud and istio
  58. HttpServletRequest、通过request获得请求头、请求体等、解决中文乱码等问题
  59. Mybatis学习笔记-一对一,一对多,多对多关联查询
  60. Mybatis学习笔记-基本概念与操作