26

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 ?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
tvautrin
  • 263
  • 1
  • 3
  • 4

8 Answers8

30

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

craftsmannadeem
  • 2,665
  • 26
  • 22
11

For me, using Docker Desktop for Windows on version 4.9.1 (81317), Windows 10 21H2, WSL 2 mode, the containers' folders were at

\\wsl$\docker-desktop-data\data\docker\containers

Slightly different from the others.

Gabriel Messas
  • 159
  • 1
  • 5
9

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

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

2019: The Docker C:\ProgramData\docker is the Root Dir reported by docker info.
2020: DOCKER_ARTIFACTS == \\wsl$\docker-desktop-data\data\docker
(as mentioned in the comments by Ricardo Rivaldo, for Docker version 20.10+)
(See also "Locating data volumes in Docker Desktop (Windows)")

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    Thank you. Indeed, I can find the logs into "C:\ProgramData\docker" if I switch to Windows containers mode. But I misspoke, I am using Windows 10 with Docker Desktop and the Linux container mode . I would like to find how to access to logs presents into /var/lib/docker/containers/[container_ID]\[container_ID]-json.log of Hyper-V / MobyVM Thanks ! – tvautrin Jun 10 '19 at 07:59
  • 1
    The fifth link really helped! Thanks! – Maria Pomazkina-Karpikova Jul 22 '19 at 07:55
  • I followed the path but logs are not there so therefore this answer is not correct. Another option is that Docker is just bad software and their documentation does not provide information on this topic. – Kaszanas Dec 26 '20 at 03:54
  • @Kaszanas Are you using WSL2? Can you try `truncate -s 0 $(docker inspect --format='{{.LogPath}}' )` (with `truncate` coming from [Git For Windows](https://github.com/git-for-windows/git/releases) `C:\path\to\Git\usr\bin`) – VonC Dec 26 '20 at 04:03
  • @VonC I am not using WSL2 to be able to set a limited amount of space and resources I allocate to Docker which I have discovered is not possible within Docker configuration when using WSL2. The command that You specified when run by Git bash returns: ```Template parsing error: template: :1:2: executing "" at <.LogPath>: map has no entry for key "LogPath" truncate: missing file operand Try 'truncate --help' for more information.``` – Kaszanas Dec 26 '20 at 04:15
  • @Kaszanas Strange: could you ask that in a separate question, with more details about your specific setup? – VonC Dec 27 '20 at 00:21
  • @VonC What about copying one of these logs to a local drive on Windows? I tried the following command but it always give "no such directory" error: `docker cp my-container:/var/lib/docker/containers/48339f914c0b86b902a0037143353e6a958729b288068a524e88879c1ffdd045/48339f914c0b86b902a0037143353e6a958729b288068a524e88879c1ffdd045-json.log /tmp` –  Feb 05 '21 at 17:27
  • @VonC Any idea regarding to this problem? –  Feb 05 '21 at 17:27
  • @Lorenzo Not on the top of my head: could you post a separate question showing which version of Windows/XSL2/Docker you are using, and showing that `/var/lib/...` does exist in '`my-container`? – VonC Feb 05 '21 at 17:36
  • There is a question about my problem. You may have a look at and reply it. Thanks in advance Von :) –  Feb 05 '21 at 18:26
  • https://stackoverflow.com/questions/66059094/docker-cannot-access-var-lib-docker-containers-no-such-file-or-directory?noredirect=1#comment116807153_66059094 –  Feb 05 '21 at 18:26
  • https://stackoverflow.com/questions/66055244/docker-error-no-such-containerpath-while-trying-to-copy-to-local-drive?noredirect=1#comment116794182_66055244 –  Feb 05 '21 at 18:26
  • https://stackoverflow.com/questions/66054166/how-to-access-docker-log-file-in-containers –  Feb 05 '21 at 18:26
  • All of three question, actually I just want to copy log.json file from container to local drive on Windows. –  Feb 05 '21 at 18:27
  • Changed (due to new version?), now is at DOCKER_ARTIFACTS == \\wsl$\docker-desktop-data\data\docker – Ricardo Rivaldo Jun 24 '23 at 00:58
  • @RicardoRivaldo Thank you for your feedback. I have included your comment in the answer for more visibility. – VonC Jun 24 '23 at 19:02
8

For Windows 10 + Docker Desktop version 3.6.0, the virtual path for logs and data (artifacts) is \\wsl$\docker-desktop-data\version-pack-data\community\docker (you can copy/paste it in Explorer navigation bar).

The logs are at \\wsl$\docker-desktop-data\version-pack-data\community\docker\containers\[containerID]\[containerID]-json.logs

and the data is under \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\[volumeID]\_data

How to get containerID:

You can find container ID (truncated) by running docker ps in a command prompt. You can also find it by clicking the CLI button on DockerDesktop next to the container name, the id will be in the title of the cmd window that will pop up. Once you have the id, you can navigate to containers\[containerID] under the artifacts directory (\\wsl$\docker-... above). The log file will have the .log extension and its name will have the containerID in it. Keep in mind that it will be an enriched json format though, so not easily readable.

How to get volumeID:

To find a container's data (for example kafka broker topics), you need to find the id of the volumes where the data is stored. For that you will need to click on the container in DockerDesktop, then click INSPECT (top right). You can then scroll down to find Mounts configuration entries. Each mount will have a volumeID (different from containerID), and that volumeID will be part of a path similar to this one /var/lib/docker/volumes/71f7a5992c58fdcf229c3848acb014712f34fab380bc7c712cf5a0a632fe9110/_data. volumeID here being 71f7a5992c58fdcf229c3848acb014712f34fab380bc7c712cf5a0a632fe9110. You can then take volumeID and navigate to volumes\[volumeID] under the artifacts directory (\\wsl$\docker-... above) where the data will be located.

ZakChar
  • 191
  • 1
  • 4
4

For Windows Users who wants to delete all Docker log files on WSL 2.

The path to the docker container is correct thx to @craftsmannadeem

\\wsl$\docker-desktop-data\version-pack-data\community\docker\containers

Here a command to execute on Windows to delete all log files:

del /s \\wsl$\docker-desktop-data\version-pack-data\community\docker\containers\*-json.log

Bye bye Docker logs:

File was deleted - \\wsl$\docker-desktop-data\version-pack-data\community\docker\containers\2012efd0ccfb8aed6291dd9a3b7b5aef507b6af4fce5b85e9306f45980db9531\2012efd0ccfb8aed6291dd9a3b7b5aef507b6af4fce5b85e9306f45980db9531-json.log
File was deleted - \\wsl$\docker-desktop-data\version-pack-data\community\docker\containers\9e627f1fe8f3c3ab85c64f85f93942d1f077e9a6e2896b51df782b0c0c3777d1\9e627f1fe8f3c3ab85c64f85f93942d1f077e9a6e2896b51df782b0c0c3777d1-json.log
File was deleted - \\wsl$\docker-desktop-data\version-pack-data\community\docker\containers\6ea8f3cb354c199bc719701f8f1e75c333f81cd2f03dca0c7a626cbcbf9ed5a0\6ea8f3cb354c199bc719701f8f1e75c333f81cd2f03dca0c7a626cbcbf9ed5a0-json.log
...
pino
  • 136
  • 6
1

If you use docker-compose with windows+wsl, In my case the log monitoring agent (also running as a container in docker) was not able to find the log files eventhough the path for logs was mounted as volume.

volumes:
   - /var/run/docker.sock:/var/run/docker.sock
   - /var/lib/docker:/var/lib/docker

The log monitoring agent could not find logs in

/var/lib/docker/containers/**/*.log

The problem in my case was, I was running docker-compose up command for the log monitoring agent from within wsl shell. When I ran it from windows powershell or cmd, the agent was able to find the logs in mounted path.

SFA
  • 63
  • 5
  • Lifesaver, I was spinning up elasticsearch, kibana and filebeat with a few services and could not, for the life of me, work out why no logs were visible within Kibana. This was the solution, simply running docker compose from powershell instead of from within my WSL instance. – James Mar 06 '23 at 21:01
0

For window system logs are located at C:\ProgramData\Docker\containers or %APPDATA%\Docker For Linux system logs are located at /var/lib/docker/containers

Vivek Raj
  • 353
  • 3
  • 3
  • 4
    I use Wİndows, but there is not such a directory C:\ProgramData\Docker\containers (no containers folder). Any idea? –  Feb 05 '21 at 17:28
  • 1
    Hi have you got the result, I too don't have containers folder. – Navi Apr 23 '21 at 17:09
0

I couldn't find where the logs were stored locally. (Good chance they aren't plain text any more. However, if you just need the output of the logs, you can run a command like this:

docker logs --details [container-name] > container-name.log

This will grab the logs for the container and write them to a log file in the current directory.

Note: The --details adds additional info to the logs like environment variables and the like, but is not required for the command to work.

ScrappyDev
  • 2,307
  • 8
  • 40
  • 60