Is there a way to save Docker container logs automatically?

时间:2019-01-18 18:49:58

标签: docker

The application that I run in a container sends its logs to stdout and this can't be reconfigured. I need these logs to be written to a file to keep them. Is there a way to automatically redirect logs from stdout of a container to a file as soon as the container starts? (I know about "docker logs" command, but it has to be controlled manually and it is no good if a container stops before logs are saved this way.) Thanks in advance.

1 个答案:

答案 0 :(得分:0)

使用entrypointstdout重定向到卷装载来修改stderr

command > /volumemount/out 2>&1

现在,所有以前到达容器stdout的docker日志都将进入主机共享卷。 https://askubuntu.com/questions/625224/how-to-redirect-stderr-to-a-file/625230