Docker exec and container logs

Source: Internet
Author: User

Looking at the history of Docker, you'll find that Docker has been emphasizing the word "application", and Docker wants to provide containerized solutions for distributed applications.

From the life cycle of the Docker application software, the development work appears to be before the Docker build, and then containerized testing, deployment, and operations are all tied to the Docker container. It must be said that Docker thinking of the application software, management process and the traditional scene has a great difference.

The biggest difference is: The closure of the Docker container operating environment. The operation of a single application allows for a lack of feature-rich services within the container. Although the user can get information about some containers through Docker, it is still not possible to know the status information inside the application directly (although Docker advocates the container to run stateless applications), such as the application container to persist the log file, the application container internal temporary storage and so on. And this information in the traditional mode, can be relatively easy to obtain.

To mitigate the barriers to use of the container's operating environment, Docker provides Docker exec commands that allow the container to execute specified commands outside the container to meet the user's needs.

Did you have Docker exec today? If you don't have one, you're worth it if you have the flexibility to pass through the container, and if so, you have to look at the following.

1. Container process tree with Docker exec

With the popularity of Docker, it is believed that more and more Docker enthusiasts have realized:

(1) Docker container is actually a number of process components;

(2) The "normal" process presents a "tree-like" relationship;

(3) The process of PID 1 in the container is the main process of the container;

(4) Once the container master process exits, all processes within the container exit.

In fact, this is rarely a problem when Docker exec is not supported before Docker 1.3, but the situation is different now, and look at:

2. Docker exec principle and container log

The principle of Docker exec can be understood in the following two steps:

  • Docker Daemon creates a user-specified process/bin/bash, so/bin/bash's parent process is Docker Daemon
  • Docker Daemon sets limits for process P5, such as the isolation Environment (namespaces) in which the container's main process P1 is joined, and is subject to resource constraints (Cgroup) as other processes

Observation, analysis principle, it is not difficult to find that the process within the container is not a tree. But why do you always emphasize "tree-like" relationships?

The answer is: tree-like inheritance, which facilitates container management. The Xiaoguanzi "Docker exec's standard output does not act as a container log" in the above article, "Docker logs implementation Profile", is responsible for taking over the standard output of the main process when the Docker Daemon creates the container master process, thus ensuring that the standard output of all processes under the container master process is taken over. However, Docker Daemon the standard output of a Docker exec process does not go into the container's log file when the new process required to create Docker exec is not associated with the container master process and is not specifically handled by Docker Daemon. 。

Although the process that Docker exec executes is also part of the container, it is more accurate to understand the log of the Docker container: The log of the Docker container is only responsible for applying its own standard output, not including the standard output of the Docker exec derivation process.

Although the title of this article is related to logs, it is almost always talking about Docker exec, which, as it is said, can be a reminder of this tried-and-do command:

  • Docker exec completes interaction inside and outside the container, but is cautious when it wants to complete a large number of standard outputs
  • Each Docker Exec,docker Daemon will be recorded once execid, avoid too frequent

From describing the principles of Docker exec to introducing some small trick of container logs, coupled with the previous Docker logs analysis, it is believed that many people will feel a fuller understanding of the logs of Docker containers.

However, the author has different views. After applying Docker, the log is still a tricky thing to do. I think: the container internal log file App.log and Docker logs still can not meet the traditional mode of log requirements.

Welcome attention to the Docker source code analysis public number

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Docker exec and container logs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.