dev_beginer
dev_beginer

Reputation: 103

is it possible to get to the logs of the container while inside a docker container?

my project is running inside a docker container - web_container and I need to get a way to get web_container's logs through the project

i tried running the command docker logs web_container >> file.log;, but as I understand it, the command is not recognized inside the docker container

is there any way to get the logs while in the container?

Upvotes: 1

Views: 4197

Answers (1)

anra
anra

Reputation: 36

Logs are stored on host, so you cannot access them in container. But it is possible to mount (docker run -v /var/lib/docker/containers:/whereever/you/want2/mount:ro) the folder inside the container (read-only preferred). By default it is here /var/lib/docker/containers/[container-id]/[container-id]-json.log. While the container ID you can obtain with cat /proc/self/cgroup | grep -o -e "docker-.*.scope" | head -n 1 | sed "s/docker-\(.*\).scope/\\1/" from inside the container. (Maybe depends on your system, anyways it is in /proc/self/cgroup).

Remark: This is a technically working answer to your question. For most use-cases the comments of David and The Fool are the more elegant way solving that.

Upvotes: 2

Related Questions