Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 views
in Technique[技术] by (71.8m points)

logging - Save docker-compose logs to a file

I have unit tests running on my build server and would like to capture the log results for analysis when something fails. I have yet to find a way to redirect the output of docker-compose logs to a file, or to find where the log files themselves actually live.

I want the equivalent of:

docker-compose logs > logs.txt

Edit - clarification:

All of my docker containers produce useful logs, which a manual run of docker-compose logs reveals. I want to script this process to save those same logs to a file that is an artifact on my build server. Essentially, the output of docker-compose logs saved to a file, however docker-compose logs never exits.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

By default docker uses the json-file driver to record your containers logs and the raw json output of the logs can be found in:

/var/lib/docker/containers/[container-id]/[container-id]-json.log

You can get this location by running:

docker inspect --format='{{.LogPath}}' [container-id or container-name]

When you run docker-compose logs [service-name], docker-compose will attach to the service (container) you reference and the LogPrinter object will output the contents of the above file, but formatted so they're easier to read.

Related docs: https://docs.docker.com/compose/compose-file/#logging


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...