Access logs of a killed docker container

后端 未结 2 969
死守一世寂寞
死守一世寂寞 2021-02-08 09:57

I recently had to clean up my full disk because of space taken by past docker containers. So I assume that I can access logs of killed containers.

For example I have the

相关标签:
2条回答
  • 2021-02-08 10:10

    As the question states that the container is killed not destroyed (removed), you can still access logs of not running containers doing docker logs <container-id>

    You can find out the ID of the not running container with: docker ps -a

    As long as you have the default docker logging driver.

    0 讨论(0)
  • 2021-02-08 10:29

    By default, destroying a container will also remove logs. If you need logs, you have to specify a --log-driver option. On a modern GNU/Linux box, use journald, for example with the docker run command

    docker run --log-driver=journald
    

    Another example using docker-compose.yml syntax :

    mycontainer:
        image: myimage
        logging:
            driver: journald
            options:
                tag: mytag
    

    Then access logs using journalctl command + filter rules

    journalctl -u docker CONTAINER_NAME=mycontainer_name
    
    journalctl -u docker CONTAINER_TAG=mytag
    

    Tag is useful when you're running a multiple service application, for example with docker-compose.

    I think in your case, the container is "recreated" using docker-compose so logs are linked to container lifetime if you don't specify logging-driver stuff.

    Also, Docker history command is linked to an image, not a container (container == running instance of a specified image)

    0 讨论(0)
提交回复
热议问题