Take you five minutes to read Docker!

Docker is what?

Open translation input Jun Docker results showed dockers, yes! Dockers is handling containers, then today talk about Docker its operation is also a container, the container it is in terms of a static image file applications, it dynamically, it is a container. Meng, right? Well, figure explained.

 

Docker is a process, from the narrow terms in a broad sense a virtual container, in fact, more professional, it is called an application container (Application Container), Docker process and the ordinary process does not make any difference, it is a common application process. But it is used to operate the image file. So Docker + build process of the application mirror file is equivalent to Docker containers. This article refers to are all talking about Docker Docker containers oh.

Before then continue below we first have to clear several important basic concepts docker bar, mirror, container, warehouse.

Mirror Docker images, is similar to a snapshot VM virtual machine inside, but much lighter than a snapshot. Snapshots do not understand? The images that can be directly interpreted as a folder. We can confirm only goal mirrored by ID or recognizable name + tag. ImagesID is a 64-bit characters, but generally we are using in front of 12 is sufficient difference.

 

As shown on the left in the red box redis: lates and red box on the right 5f515359c7f8 uniquely represented as a single image. So we generally mirroring can be named similar centos: latest, centos: centos7.1.1503 and so on.

Mirroring is hierarchical, with a base image contains only operating system, such as centos mirror; there is a mirror middleware, such as redis such as database mirroring; and finally the application image, refers to the specific application services, and application images can be very rich, at any time You may publish, in turn superimposed between the three.

So when we mirror constructed using Docker, each command will form a new image layer on the basis of a previous command. Below, the base image is centos mirror, the mirror is intermediate two circle red, purple ring is mirror applications. Wherein redis + centos such superimposed image can be a combination of middleware for A Service B Service or use, such compositions more flexible overlay. And one still image can be pulled from Docker hub public warehouse.

 

Container Docker containers, you can create a mirror from the container, it is like creating a virtual machine from the snapshot, but lighter, faster startup, Kai seconds. Application is running in a container, an analogy, you first download a mirror image of Ubuntu, and then install mysql Django application and its dependencies, to complete modification thereof Ubutun mirror, a very personal feel perfect application image generated ! Put the mirror to share for everyone to use, it will generate a container through the mirror. Django service will run after the vessel started.

 

The above also said, and container is a separate closed containers, but also need to provide services, so Docker allow certain ports open container, starting Docker, we can be certain port mapping container to the host any of the above a port, so if several services require port 80, then the external container port is 80, but on top of that is mapped to host any port, it will not conflict, there is no need to resolve the conflict by proxy . External port and container port mapping host may be accomplished by the following command.

Start docker container
docker run -d -p 2222: 22 --name container name image name
-d guard vessel, is running in the background, the command window to exit the vessel will not stop
-it interactive command window to exit the container vessel stopped running
- p host port and container port mapping
8081: 80 host port: the port of the container disclosed

 

 

Warehouse Docker registeries, docker warehouse and storage container warehouse is the same, but docker use to store images. The presence of public and private warehouses points, public warehouse docker hub provides a lot of image file, those images can directly pull down the run, you can also upload your own image to docker hub above. But you can also build their own private repository for the project management team.

Combined with the basic concepts described earlier, we can use several concepts docker approximately string together between how they operate, that is, Docker life cycle. See the figure, mainly three steps.

 

1, developed to build the mirror and mirror push Docker warehouse
2, testing or operation and maintenance Docker from the warehouse to the local copy of the mirror
3, the container through the opening Docker image files and provide

Why use Docker? What more competent?

Why use Docker? This is from the current pain points of software industry in terms of starting a software update is released and deployed inefficient, tedious process and requires manual intervention, 2, the environment is difficult to guarantee the consistency, 3, migrate between different environmental costs too high. With Docker can solve the above problems to a large extent.

First, the use of Docker's extremely simple, from the development point of view is that three steps: build, transport, run. The key step is to build links, namely packaged mirror file. But from the testing and operation and maintenance point of view, it is only two steps: Copy, Run. With this mirror, where you want to copy you can run, and completely independent of the platform. Meanwhile Docker this container technology to isolate the independent running space, and other applications will not compete interaction between applications and the system resources do not need to consider, think about the fun.

Secondly, because when building mirrored on the handling of finished service program for all system-dependent, so when you use them, you can ignore the dependence and the development of language original program. Testing and operation and maintenance, the more focused on their business content.

Finally, Docker provides a way to manage a development environment for developers, and testers to ensure that the environment in terms of synchronization, operation and maintenance personnel to provide a standardized deployment process to be portable.

So, Docker can be doing, summarized as follows:

  • Simple and easy to build distributed
  • Isolation Applications wean
  • After measuring pins on the rapid deployment

Docker is a process-level lightweight virtual machine, the virtual machine and traditions so what difference does it make?

Docker super lightweight virtual machine, it is just a process. With traditional virtual machine such as VM has a huge difference, the difference look:

 

We look at the difference between the two, because of the need to implement the VM Hypervisor virtualization hardware, and also equipped with its own operating system, which memory for the virtual machine operating system is relatively large, an operating system has several G, naturally in the start-up speed and resource utilization, and performance overhead is very large, if locally or PC, then the impact is not so big, but in the cloud is a very large waste of resources.

Many times we do when things do not consider the issue has nothing to do with the thing itself, such as airplanes do not consider whether or not to dive the aircraft, for we are many applications of mobile Internet, it rarely involves the parts of the operating system , in fact, our main concern is the application itself, while the upper VM virtual machine runtime libraries and application is running, the entire space of the virtual machine is very large, but after the emergence of technology Docker container technology, eliminating the need for operation this layer system, separated from each other and share the host operating system and runtime library between a plurality of containers.

Therefore, with respect to container VM Docker application has the following advantages:

  • Start fast, it is essentially a container starts a process to open it, so all second start, while the VM is usually longer.
  • High resource utilization, a common PC can run hundreds of containers, you try to run ten VM.
  • Small performance overhead, VM often requires additional CPU and memory to complete the function of the OS, which occupies part of the additional resources.

Therefore, many mobile Internet applications or back-end cloud computing node docker can be used to replace a physical machine or a virtual machine. Such as Tencent map of many back-office services basically migrated docker deployed.

Docker is Gesha architecture? What is the underlying technology used?

He said in front of so many, and it is still smoke and mirrors. The following details about the technical architecture, the underlying technology is used to achieve what so many advantages of the above?

Docker technology architecture diagram:

 

Docker dependent from the underlying technology point of view, Docker original ecology is not run directly on the Windows platform only supports linux system, linux kernel because Docker dependent on three basic techniques, namespaces act as the first level of isolation, is Docker container isolation, so that the container has a separate hostname, ip, pid, while ensuring a container to run a process and can not be seen or affect other processes outside of the container; Cgroups is a container for host resources used for accounting and restrictions The key function.

Such as CPU, memory, disk, etc., union FS mainly on the mirror image of this one is for support, using the copy-on-write technology, so that we can share a layer for layer, then some of the differences can be differences in memory storage, Libcontainer is a library, the above three techniques is to make a package.

Pulling container Docker engine for controlling the operation of the vessel, and the image file.

Docker gnaw installed it? Docker how to use it?

Before installation, we first make sure your linux kernel version is higher than 3.10, and the system is 64-bit, in order to experience Docker oh.

By uname -ir view meets the requirements.

 

Docker installation

Installation docker by way of the script is very simple.

1. Get the latest installation package docker

nicktang@nicktang-virtual-machine:~$ wget -qO- https://get.docker.com/ | sh

Enter the current user's password, it will download and install the script Docker and dependencies.

On display showing the contents to show that the installation is complete.

2, start the background service docker

root @ nicktang-virtual-machine: / data # sudo service docker start # start the daemon
root @ nicktang-virtual-machine: / data # docker -v

You can see the version number, indicating a successful installation docker. Simple, right! At this point he sent a mirroring. Make your own from a public warehouse or pull it with your friends.
root @ nicktang-virtual-machine: / data # sudo service docker stop # closed daemon

Docker use

Docker use, we major additions and deletions from the [search] says several ways how to use docker, why did not [change] it, because in my opinion docker container if there are problems, and there is no need to fix, directly to the vessel to stop and delete, restart, so faster. So we only need to master a few basic commands, as follows.
[Check] to see the existing local mirror Docker images

[Run by] a mirror, that is to start a container docker run image name, such as we run docker run centos
typing this command when the operation is completed the three samples
1, check whether there are local hello-world this image, there are -> skip Step no -> sequentially performed
2, docker hub to automatically download the image
3, is loaded into a container and put the image run

Then docker images when viewed locally increases the centos mirror.

Tag is the latest, says the latest version of centos system image. Because I will not take the image from the docker hub pull, so increasing operator [] inside.

[Increase] pulled the specified image file docker pull mirror name: TAG

That runs directly above by way of pulling docker hub is the latest in a mirror, but sometimes I want to pull the specified image file you need to use docker pull command to pull. Because pulling image files from the official, usually a relatively slow, so we can pull from the domestic warehouse mirrored by accelerator technology.
[Check] to see all of the containers docker ps -a can be used to view all of the containers, including the operation and has been stopped.

The first field is already initiated container ID, the second field is the mirror image based on which the container is generated. But what this command is only temporary to start about the vessel, above the figure status is exited (0), represents a container is the exit status. If you want to container running in the background, so we need to start guard vessel can, just add a -d parameter in the startup command, namely docker run -d centos on it.

[Check] view specific information docker mirror / mirror inspect the container ID (image name) / container ID (container name) docker inspect CentOS

This command returns a string json mirroring or more information containers. These include a lot of information ID, ip, version, main container, etc. We can be secondary development based on that information. On the basis of this command on adding a -f parameter to specify that we can get the information they need, such as access to redis container of IP addresses, memory information, CPU usage. docker inspect -f '{{.NetworkSettings.IPAddress}}' [ID / Name]

[Check] docker run -it centos into the container i.e. container starts an interactive
-it completed container terminal and the associated current terminal, the terminal will display the current that is switched to the display of the container terminal.

 

View container directory structure, the directory structure and find exactly the same physical machine, which is why some reason called docker container, also known as virtual machine friends. Exit to exit the container terminal.

 

[40] delete container, docker rm container ID, you can delete multiple containers across multiple container ID can be separated by a space.

 

How Docker complete with continuous integration, automatic delivery, automatic deployment?

This is the first meeting of what automation is not talking point, what sustained, are embarrassed. So, we have to look at continuous integration, automatic delivery, automatic deployment. But it says so much, we did not find that there are three things Docker function ah, yes, Docker is not have this feature, but you've completed these steps are dependent on three things automated Docker's. Docker is the basis for these processes to achieve, just as software development, software code is fundamental, is to assist the development tools. All build a complete automated process also need to github + jenkins + registry three things help.

Continuous integration and automatic deployment of the principles as shown below:

 

  1. RD git repository to push the code or other code server svn above, git server notifies jenkins by hook.
  2. jenkine cloned git code to local, and compile dockerFile file.
  3. Package generate a new version of the mirror and pushed to the warehouse, delete the current container, re-run the new version of the image.

In the whole course of just typing three RD command Git add *; Git commit -m ""; Git push to complete continuous integration, automatic delivery, automatic deployment. Through the magic behind the case demonstration of this process!

Docker also can easily automatic expansion, oh, two ways typical automatic expansion of a docker is the capacity to expand, while another is to expand the number of nodes docker. The first would modify configuration files, simply copy the second run to complete the expansion node.

to sum up

Docker is good, but do not drink more Oh! Although Docker ultra-lightweight, but does not recommend too many applications deployed on top of a machine, and the deployment of differentiation must be deployed, what this means is that a large number of calculations, and memory require large, frequent IO operations inconsistent demand on system resources deployed on the same host.

Published an original article · won praise 0 · Views 424

Guess you like

Origin blog.csdn.net/qq_37983000/article/details/103197954