Access logs of a killed docker container

后端 未结 2 968
死守一世寂寞
死守一世寂寞 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: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)

提交回复
热议问题