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?
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.