Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why do I need Docker?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

Only a bald head can get stronger.

The text has been included in my GitHub warehouse, welcome to Star: https://github.com/ZhongFuCheng3y/3y

You may have heard of Docker (in forums, recruitment skills, communication groups, etc.). If you don't know Docker, you won't be embarrassed to brag when surfing the Internet.

So I learned Docker these days, summed up the relevant knowledge of the introduction to Docker, and shared it with you (so that we can brag together).

I need a doctor,call me a doctor. I need a doctor, doctor, to bring me back to life.

First, why do you need Docker

Official introduction (Chinese version):

Docker is the world's leading software container platform.

Developers can use Docker to eliminate the problem of "working on my machine" in collaborative coding.

Operation and maintenance staff can use Docker to run and manage applications in parallel in an isolated container to obtain better computing density.

Enterprises can use Docker to build agile software delivery channels to release new features for Linux and Windows Server applications with faster speed, higher security and reliable reputation.

1.1 Environment (switching / configuration) hassle

Generally speaking, when we write programs, we can come into contact with several environments:

The environment in which you write your own code is called the development environment.

The environment in which the test is run is called the test environment.

What can be used for external use after testing is called the production environment.

In fact, in learning programming, we waste a lot of time on the "environment":

If I reinstall the system now and I want to run my war/jar package, I have to install various environment variables such as JDK, Tomcat, MySQL and so on before I can run.

Happily follow the steps given by the blogger to write Demo, but there is always Bug. Here I also categorize version / dependency into the scope of the environment.

It's not easy to run in the test environment, and there are all kinds of mistakes in the production environment!

Follow the teaching video to do distributed / cluster projects, run a bunch of virtual machines, and each virtual machine has to install the corresponding environment.

So there's a joke, "Don't tell the programmer that your code has bug":

His first reaction is that there is something wrong with your environment, and the second is that you are stupid and can't use it.

You have to say to him: "how this program works is not as expected. Is there something wrong with my operation?" .

The product will first think, "Oh, my God, is this a bug?"

1.2 isolation is required between applications

For example, if I write two applications (websites) and the two applications are deployed on the same server, what might happen?

If there is a problem with an application, the CPU accounts for 100%. Then another app will also be associated, and it will cool down with it.

These two applications are completely different technology stack applications, such as a PHP, a. Net. The various dependent software of the two applications are installed on the same server, which may cause various conflicts / incompatibility, which may be very troublesome to debug.

II. How does Docker solve the above problems (switching / configuration)

I wonder if you have ever installed a system, such as installing a Linux virtual machine or reinstalling a Windows system, all of which need to be mirrored.

With this image, we can run the image to install the system (omit the N next step here), and our system is installed. Generally speaking, the images we download from official channels are pure. For example, go to the official download Windows image, after installation, there is only one recycle bin on the desktop.

However, students who have known how to install the system may know that some images may still have 360 these software after installation, but the system has really changed. To put it simply, these images add other things (such as 360 software, Tencent, Qianqian silent listening, etc.).

Docker is the same way of thinking, we can build (package) our desired environment into an image, and then we can push (publish) to the Internet. Want to use this ring

At the time of the situation, it would be good to pull one on the Internet.

With Docker, when we build the environment, the way we used to be is different.

Before: a war package was built in the development environment and wanted to run under Linux. We have to download Java, Tomcat and MySQL in Linux, configure the corresponding environment variables, and drop the war package into the webapps folder of Tomcat before we can run.

Now: pull an image directly under Linux (all kinds of environments are ready), run the image, and throw in the war package.

It only takes a second or two to run the image of Docker, which is very convenient.

2.2 resolve isolation between applications

At this point, we have to come up with a concept that you may not know: LXC (Linux Containers)-> Linux container.

2.2.1Linux container

In the Linux kernel, the cgroups function is provided to achieve resource differentiation. It also provides the function of namespace (namespace) partitioning, so that the operating system environment seen by the application is divided into independent regions, including process tree, network, user id, and mounted file system.

To put it simply: LXC is a user interface that contains features for the Linux kernel. With powerful API and simple tools, it makes it easy for Linux users to create and host systems or application containers.

2.2.2 back to Docker

When we look through the official documents of Docker, it is also easy to see the nouns cgroup and namespace:

Source Wikipedia:

Early versions of Docker used LXC as the container execution driver, though LXC was made optional in v0.9 and support was dropped in Docker v1.10.

Lxc is a basic component of the earlier version of docker, and docker mainly uses its control over two kernel features, Cgroup and Namespace. The new version of Docker has removed the support for LXC.

2.2.3Docker in Windows and Mac

As mentioned above, Docker uses Linux's cgroup and namespace technologies to achieve application isolation. Can Windows and Mac users use Docker?

Previously, Windows and Mac used Docker to actually run a layer of Linux virtual machines.

For example, Docker Toolbox is installed under Windows, and it needs Oracle Virtual Box to run Docker.

Now, both Windows and Mac support Docker natively. However, some installation conditions are required. For more information, please see the official website.

For example, Windows:Docker for Windows requires 64bit Windows 10 Pro and Microsoft Hyper-V

Reference:

Windows native Docker is officially commercially available

Http://blog.daocloud.io/windows-docker/

III. Virtual machines and Docker

When it comes to application isolation and mirroring, I think of virtual machines. The second half of this year (omitted here). .), the style is in bloom (omitted here). If I am not good at writing an article, I need to apologize to XX.

It is estimated that everyone has used the virtual machine, the virtual machine can also achieve the isolation of applications, the installation of specific images can also run out of the environment we want. Virtual machines have been developed for a long time, so why do we need Docker?

This part is also introduced on the official website:

Http://www.docker-cn.com/what-container#/virtual_machines

To sum up: Docker containers are much lighter than virtual machines!

Last

What can Docker do?

Package a whole set of environment into a mirror image, there is no need to configure the environment repeatedly, and solve all kinds of problems brought by the environment.

Docker containers are process isolated, and no one affects each other.

In fact, this article is mainly about why we need Docker (before we learn a technology, we must know what it is for), some of the concepts and commands of Docker have not been introduced (save for the next article). If you haven't seen the docker application scenario from moving house to container technology, you can take a look at it first.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report