Save docker-compose logs to a file

后端 未结 5 559
情歌与酒
情歌与酒 2020-12-12 23:57

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

5条回答
  •  情深已故
    2020-12-13 00:38

    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

提交回复
热议问题