How can I access Docker containers Folder and files from Windows file explorer?
-
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?– danielornDec 31, 2018 at 13:28
-
1That link may help :michaelcrump.net/part6-docker– pungggiJul 6, 2020 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.– RobbiegodNov 3, 2022 at 17:12
4 Answers
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.
-
1This 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. Apr 30, 2020 at 20:50
-
You need to edit
\wsl$
to\\wsl$
. Source text is\\wsl$
that interpreter translates to\wsl$
due to escaping.– cdalxndrOct 18, 2020 at 13:02 -
Another related question's reply answers this: https://stackoverflow.com/a/64418064/1115220
\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\
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
-
Can u clarify what the ./ current directory is? Can u provide some example? @csandreas1 Nov 3, 2022 at 17:14
-
1The directory where you have the docker-compose.yaml file. Usually in the project root Nov 3, 2022 at 20:33
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
-
5I 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.– ArikAug 23, 2019 at 8:25
-
1Came to this page searching for the OP. Disappointed by answers that show how to access host's files from container.– BarryPyeOct 3, 2019 at 18:42
-
1If 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.– ThomasOct 10, 2019 at 17:21
-
2
-
3If 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. Apr 1, 2020 at 3:56