简体   繁体   中英

Is there a way to save Docker container logs automatically?

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.

Modify the entrypoint with stdout and stderr redirection to a volume mount.

command > /volumemount/out 2>&1

Now all the docker logs which used to come to stdout of the container will come to the host shared volume. https://askubuntu.com/questions/625224/how-to-redirect-stderr-to-a-file/625230

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM