42

How can I access Docker containers Folder and files from Windows file explorer?

xpt
  • 20,363
  • 37
  • 127
  • 216
Nafis Abdullah Khan
  • 2,062
  • 3
  • 22
  • 39
  • Are you looking to browse the whole filesystem of the container from the windows file explorer, or would a host volume mounted as a volume in the container suffice? – danielorn Dec 31 '18 at 13:28
  • 1
    That link may help :https://www.michaelcrump.net/part6-docker/ – pungggi Jul 06 '20 at 10:27
  • i know i would like access the files for the website that is on the Docker server in windows, just that website folder, nothing else. I don't need access to the server files. – Robbiegod Nov 03 '22 at 17:12

5 Answers5

34

If you are running Docker Desktop on Windows, Docker containers don't run natively on the local filesystem, but instead on a hyper-v virtual machine or via WSL2.

Hyper-v (legacy)

In theory, if you were to stop the hyper-v vm, you could open up the vhdx, and if you had the right filesystem drivers, mount it and see the files inside. This is not possible to do while the virtual machine is running. By default the OS that runs for Linux container mode is named "Docker Desktop", but runs busybox.

The file could be found here:

C:\ProgramData\DockerDesktop\vm-data\DockerDesktop.vhdx

WSL2 (modern)

WSL things are slightly different, but not much. You are still effectively working with a virtual environment.

One of the nice advantages of WSL however, is that you can actually browse this file system naively with Windows Explorer.

By browsing to \\wsl$ you will be able to see the file systems of any distributions you have, including docker-desktop.

The docker filesystems on my machine seem to live in:

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

However, the overlay 'merged' view, which shows the original file system with your changes, doesn't seem to work via windows explorer and gives you a blank window. You can however still see the 'diff' folder, which contains your changes.

You can open a terminal to either of these instances by using the wsl command, from powershell.

Access via Docker

If you wanted to have a look at this Docker OS and filesystem, one way would be to spin up a container, that has access to the OS at the root, something like:

docker run -it --mount type=bind,source=/,target=/host ubuntu /bin/bash

This should drop you into a Ubuntu docker container, with a Bash terminal, which has the root of the hyper-v container (/), mounted on the path '/host'. Looking inside, you will find the Busybox filesystem of the virtual machine that is running docker, and all the containers.

Due to how docker runs, you will be able to access the filesystems of each container. If you are using the overlay2 filesystem for you containers, you would likely find the filesystem layers here for each container:

/host/var/lib/docker/overlay2

If the files you want to browse through in windows explorer, you should be able to configure a samba export of this folder, that is accessible from the host machine, that is accessible while this container is running.

If the goal however is to be able to browse/edit files on the local OS, and have them update inside the container, normally the easiest way to do this, is to mount local directory into the container. This can be done similar to the example above, but you first need to go into the Docker Desktop settings, and enable the mounting of the shared drive into the host virtual machine, and then provide the volume argument when you spin up a container.

If you are using WSL2, there are a few more options available to you, as you can keep your projects inside the WSL layer, while interacting with them from the host OS or via docker. Best practice for this is still in flux, so I'm going to avoid giving direct advice here.

KHobbits
  • 506
  • 5
  • 7
  • 1
    This should be accepted as the answer. I could find the filesystem of all Linux containers after spawning the Ubuntu container mentioned in the answer, and going to /host/var/lib/docker/overlay2 inside the container. – Jaywalker Apr 30 '20 at 20:50
  • You need to edit `\wsl$` to `\\wsl$`. Source text is `\\wsl$` that interpreter translates to `\wsl$` due to escaping. – cdalxndr Oct 18 '20 at 13:02
  • How to get an ID in overlays2 folder for some container? – mlt Jan 25 '21 at 08:45
10

Another related question's reply answers this: https://stackoverflow.com/a/64418064/1115220

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

JasonS
  • 7,443
  • 5
  • 41
  • 61
1

When running Windows container on Windows Docker Desktop, I was able to see all image files here:

C:\ProgramData\Docker\windowsfilter

(requires admin rights to access, and it would be unwize to delete/modify anything there)

Further, with WizTree tool, it's easy to see real sizes of each image layer and even find which specific files contribute to layer's size.

Codeguard
  • 7,787
  • 2
  • 38
  • 41
0

I'll give WordPress app as an example by showing a sample of the docker-compose.yaml file. In order to have project files shown in windows from docker container, you'll need to use ports and volumes

Notice volume and ports.

port 8000 from the local machine maps to 80 within the container.

as for volume, ./ current directory on windows maps to the container image files.

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes: ['./:/var/www/html']
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
csandreas1
  • 2,026
  • 1
  • 26
  • 48
-1

You should use a mount volume. In your docker run .... command, you may specify a mount volume. The syntax is as follows:

-v /host/directory:/container/directory

An example:

docker run -it -v C:\Users\thomas\Desktop:/root/home --name my_container image1

This would allow the container to write files to /root/home and have them appear on the user thomas' desktop

Thomas
  • 550
  • 5
  • 17
  • 5
    I believe the OP wants to explore the files from the container, using windows explorer. Your solution will allow seeing the host files inside the container, not the other way around. – Arik Aug 23 '19 at 08:25
  • 1
    Came to this page searching for the OP. Disappointed by answers that show how to access host's files from container. – BarryPye Oct 03 '19 at 18:42
  • 1
    If you write files within a container to a directory, and are using a mount volume, you can see all of them. You are then able to view the mounted directory via File explorer. However, it really isn't that hard to traverse a file system via command line. – Thomas Oct 10 '19 at 17:21
  • 2
    OP request was specific: **Windows file explorer** – BarryPye Oct 14 '19 at 13:58
  • At this time, that is not possible and I doubt heavily it ever will be. I attempted to provide an answer that allows using the explorer to view the files that are mounted as that seemed as close as I could get :) – Thomas Jan 10 '20 at 20:06
  • 3
    If that's the case, that should be part of your answer. I would say the most important part of the answer. At the moment it's misleading. – Joel Roberts Apr 01 '20 at 03:56