The Docker container log thing.

Source: Internet
Author: User

If the time can be reversed, the real world every step can be broken down to the smallest, recorded, is the log, all things the same day.

In the face of history, examine the log, you can choose to forget, you can choose to remember, experienced, can choose to cherish, also can let it dust-laden.

What about Docker containers? The log is like a timeline, where you are or not, and he is there. Some people have a good faith in it, but others are free to do it. If you do not believe, you can recall that you are good to the log of the Docker container.

1. Log of legacy applications

If not by the past hurt too deep, stepping into a new world, you should still miss the past it. The New World "Temptation" and the new rhythm, believe that still can not cover up the old letterpress. How is the life of application recorded in decades?

1.1 Many people pay attention to the results, the process may be indifferent, the application of the log may be with the standard output standard error (stdout, stderr), can not capture, can not be fixed, the result is very jietan; 1.2 Tea Tim Fragrant, Bellyful's wit may poem a song, the book in the interior wall. The night of the evening was aroused by a revisit. The same applies to the log, and the person who has the heart will also record the log (poem) and persist it to a place (the book is inside the wall) for easy access. 1.3 Anytime and anywhere can recite inscriptions, the ancients traveled thousands of miles, I believe it is difficult to all poem all memory. No matter how far, if the memory can be hidden in a convenient future of the United States to remember, the best policy. Ten years ago, teacher Chen that computer did it; last year, the elder cousin's cell phone also helped her to do. Life is so, not to mention the diary. Log log, in fact, the application of the log can also be sent to a place, centralized processing. Log of the 2.Docker era

The log of the Docker era, the pace did not cross too much, after all, security first. However, there is no denying that the era of development always has the bright spot that surprises you.

If you are an application in a container, even if you are toss, or if you are free and easy, Docker containers will record your drip, as long as you are wrong about the standard output standard action. (All standard output standard errors of Docker containers will be taken over by Docker Daemon)

If you are a reader of countless, boxing Nanshan, kicking the North Sea, the world is the world of the Docker container, you in Beijing one night, perhaps the next day in Shanghai you have been sober as ever; on the third day of business in Hangzhou, you do not remember yesterday in Shanghai is a few star hotel. (The Docker container itself should be as stateless as possible, the application of persistent logs in the container has a state, frequent migration is not appropriate for container log management).

If you have a kidney machine, if you continue to support big cousin. In a Docker container, it's easy to pass the container's hang around experience to the cloud, so you can see it someday. (Docker container Application log, if sent to the centralized log processing center, it is the best policy, easy unification; The problem is high cost, have money to buy kidney machine, also need to unify the standard)

3. Get the Docker container persistence log

Read the world countless, but it is difficult to remember the drip, presumably not the king of Taiwan's wish. Wake up, how to learn all about Beijing one night, now give June a bit of skill, so easy to transport applications in the Docker container persistent log.

If you are already familiar with the principles of Docker logs, then the standard output standard error of those things, it seems to you naturally. If you add some dockerfile cmd knowledge, the following will naturally be understood.

Goal:

Pass the application persistence log file inside the Docker container through standard output.

Method:

Simple refactoring application dockerfile cmd instructions.

Problem hypothesis:

The cmd command that originally applied Dockerfile was cmd ["Python", "app.py"], and the path to the application of the print log was/var/log/app.log.

Specific implementation:

The first step: in the original Dockerfile directory, create a run.sh file, the file content is:

' #!/bin/bash

Tail-f/var/log/app.log &

exec python app.py

Step Two: Modify the Dockerfile, delete the original CMD, replace with three instructions.

Instruction one: ADD run.sh/;

Instruction two: RUN chmod +x run.sh;

Directive three: CMD ["./run.sh"]

Principle Analysis:

A background process is initiated in run.sh, forcing the content of/var/log/app.log to be transferred to standard output using the tail command.

The EXEC command is then used to run the Python app.py as the container's main process.

With the advent of the new era and the great convenience of the technological revolution, it may also be necessary to change the way it was originally done, as did the log management of Docker containers. After all, one night in Beijing, just take a shot at the Docker container, say action to him, the manpower and resources are saved, definitely more than one minute of three Li Tun relaxed a lot.

Presumably, the cost should not be too high.

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.

The Docker container log thing.

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.