简体   繁体   中英

How to save docker container logs on the machine instead of in the container

I have some tests that i am running using docker-compose. The problem is that the docker logs are saved within the container (which makes debugging complicated).

I am looking for a way to configure docker-compose to save all logs on the machine where i am running the tests, instead of the container. Preferably some configuration of docker-compose.yml file, but i am open to any suggestion

It is not docker-compose , who saves your logs and has to be reconfigured. It is docker itself or your service, running inside that docker, depending on what logs do you mean.

If you are talking about docker logs, you should refer to docker log driver configuration page: https://docs.docker.com/config/containers/logging/configure/

If you are talking about logs, produced by your services , just mount writable volume from your host pc into container, and configure your software to log into that folder. You can achieve this like the following code does:

docker-compose.yml:

...
my-service:
  image: xxx
  entrypoint: ["sh", "-c", "echo 'Hello World!' > /path/inside/docker/some_log_file" ]
  volumes:
    - /path/on/host:/path/inside/docker
...

you service now should just log into /path/inside/docker/some_log_file .

On host machine you will see all these files in /path/on/host

I guess the scenario you are looking is you have docker containers scattered accross multiple host machines. so probably you need to make the docker container to the host machine volume and see if you can map the host volume to a share file system.

or write some scripts that are running on the docker host machines to copy the log files from a mapped docker volume on the docker host to a remote location of your choice using scp command etc.

or use some log aggregation frame works https://stackify.com/log-aggregation-101/

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