Search code examples
dockerloggingdocker-swarm

How to docker container logs to a local file?


I need to look up into docker logs for some days ago and checking by docker service logs SERVICE | grep WHAT_I_NEED takes forever so I want to download the container logs from docker swarm and check those locally. I found that the container logs in Swarm can be found by:

docker inspect --format='{{.LogPath}}' $INSTANCE_ID

but I can't find a way to download the log from the location.

Doing: docker cp CONTAINER_ID:/var/lib/docker/containers/ABC/ABC-json.log ./ tells me that the path is not present. I understand that this path is in Swarm but then how to get the log from the container itself? Or is there another way to copy this file directly to a local file?


Solution

  • Try running this one from your terminal:

    docker logs your_container_name 2> file.log
    

    This will redirect the container logs to the local file file.log