Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 and Docker container logs / Docker Logging driver

I'm using Windows 10 with native docker installation.

I'm looking for the location where docker save the containers logs.
In Linux, the Docker containers log files are in this location:

/var/lib/docker/containers/container-id/container-id-json.log

But where can I find it in windows 10 ?

like image 591
tvautrin Avatar asked Jun 09 '19 20:06

tvautrin


People also ask

How can I see the logs of a Docker container?

First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.

What is the default logging driver Docker?

As a default, Docker uses the json-file logging driver, which caches container logs as JSON internally.

Where are Docker logs stored on disk?

The default logging driver as I mentioned above is a JSON file located on the local disk of your Docker host: /var/lib/docker/containers/[container-id]/[container-id]-json. log.


2 Answers

For Windows 10 + WSL 2 (Ubuntu 20.04), Docker version 20.10.2, build 2291f61

Lets DOCKER_ARTIFACTS == \\wsl$\docker-desktop-data\version-pack-data\community\docker

Container logs can be found in the following location

DOCKER_ARTIFACTS\containers\[Your_container_ID]\[Your_container_ID]-json.log

Here is an example :

enter image description here

like image 176
craftsmannadeem Avatar answered Oct 17 '22 19:10

craftsmannadeem


Check first if those logs are in (as suggested here):

C:\ProgramData\docker\containers\[container_ID]\[container_ID]-json.log

The Docker C:\ProgramData\docker is the Root Dir reported by docker info.

Regarding Docker Linux through Hyper-v, check if "How to Delete Docker Container Log Files (Windows or Linux) " can help (from Jon Gallant):

  1. Run docker inspect to find your Docker log file location
  2. Find the “Docker Root Dir” Value, mine is /var/lib/docker

Your docker log file path should be /var/lib/docker, but if it isn’t, then change it in the command below.

find /var/lib/docker/containers/ -type f -name "*.log"

https://blog.jongallant.com/2017/11/delete-docker-container-log-files/000330.png

The command you see in this image is based on "How to SSH into the Docker VM (MobyLinuxVM) on Windows"

We aren’t technically going to SSH into the VM, we’ll create a container that has full root access and then access the file system from there.

  • Get container with access to Docker Daemon
  • Run container with full root access
  • Switch to host file system

Open a Command prompt and execute the following:

docker run --privileged -it -v /var/run/docker.sock:/var/run/docker.sock jongallant/ubuntu-docker-client 
docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh
chroot /host

Execute the find command there, and you should find the logs.

like image 8
VonC Avatar answered Oct 17 '22 18:10

VonC