stackoverflow.comquestions33848947accessing-docker-container-files-from-windows
stackoverflow.comquestions33848947accessing-docker-container-files-from-windows
Asked 7 years, 6 months ago Modified 4 months ago Viewed 56k times
40
How can I access Docker containers Folder and files from Windows file explorer?
windows docker
ShareImprove this questionFollow edited Apr 24, 2020 at 2:16 asked Nov 21, 2015 at 21:46
xpt Nafis Abdullah Khan
19.8k 36 121 211 1,962 3 21 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, 2018 at 13:28
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 3, 2022 at 17:12
5 Answers Sorted by: Highest score ﴾default﴿
34
Your privacy
If youBy clicking
are “Accept
running all cookies”,
Docker Desktopyou
onagree Stack Exchange
Windows, can store cookies
Docker containers on your
don't run deviceon
natively and
thedisclose
local
information in accordance with our Cookie Policy.
filesystem, but instead on a hyper‐v virtual machine or via WSL2.
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.
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.
\\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.
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.
ShareImprove this answerFollow edited Oct 19, 2020 at 17:49 answered Apr 22, 2020 at 21:34
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, 2020 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, 2020 at 13:02
How to get an ID in overlays2 folder for some container? – mlt Jan 25, 2021 at 8:45
8
\\wsl$\docker‐desktop‐data\version‐pack‐data\community\docker\volumes\
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.
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
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 – Robbiegod Nov 3,
2022 at 17:14
1 The directory where you have the docker‐compose.yaml file. Usually in the project root – csandreas1 Nov 3,
2022 at 20:33
‐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:
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, 2019 at 8: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 3, 2019 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, 2019 at 17:21
2 OP request was specific: Windows file explorer – BarryPye Oct 14, 2019 at 13:58
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 1, 2020 at 3:56