Installed docker desktop for windows 10
Used powershell to run docker containers ( ubuntu )
Now, I want to browse to /var/lib/docker --> want to browse to overlay2 to check layers.. /diff folder etc.
If i access /var/lib/docker folder - powershell complains that this folder does not exist.
Other piece of info: I have already checked out the disk image location which is mapped for docker desktop. It is a vhdx file.
I was not able to open it with Oracle virtual box - it says it is not a supported version file.
I tried opening in Hyper V manager, the VM is getting listed: DockerDesktopVM.
But my objective is to do SSH and browse /var/lib/docker folders..
(This is for case of WSL2. It is my answer to a similar question)
Docker images are managed by docker's own VM. The path /var/lib/docker given by "docker info" is relative to docker's host file system, not your container's file system. The mount points are different for them. You can view docker's host file system in either of the following ways:
You can mount the host file system to a container directory. Such as,
docker run -v /:/data -it ubuntu /bin/bash
This command runs a shell in Ubuntu docker image, mounting docker's file system to /data directory. There you can find a complete file system under /data, including the ./var/lib/docker. If you want, you can "chroot /data" in the shell prompt to have a better view.
When docker is enabled with your distribution in WSL2, you can always check your containers in your distribution /mnt directory. Docker has mounted everything for you.
/mnt/wsl/docker-desktop-data/data/docker
If you are seasoned enough, you may find the actual location of the virtual disk of all the data in your Windows directory.
C:\Users\your_name\AppData\Local\Docker\wsl\data\
Or probably just for fun:
\\wsl$\Ubuntu\mnt\wsl\docker-desktop-data\data\docker
Unfortunately I haven't tried to dive into them.
As stated on This page of docker forums you can run plain debian docker image with shell and change it's namespace to docker host.
The terminal command you need to run is:
>> docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -i sh
as I understand after running debian image as terminal (-it option), you need to call command nsenter with specified parameters to change namespace to host machine. After this your container becomes Docker host and you can view all it's files.
after this command you can access docker images simply by calling:
>> cd ls /var/lib/docker/
In the left pane of your windows file explorer, you can find all you computer drives. If you have installed WSL (when you setup your Docker), you will see this Linux pinguin icon.
Select the docker-desktop-data directory and inside it, the data directory. Within the data directory you will find there the docker directory and the volume generated by docker run ... -v command.
shortcut would be: cd \\wsl.localhost\docker-desktop-data\data
Related
I have tried this example out on a windows 10 box which has WSL2 installed and integrated with the latest Docker version. After following the steps in the example and downloading the code in the linux subsystem, I am able to build the image and run the container. The website is also available on the browser when I browse to it on a browser running on Windows 10. However, when I create a file or folder in the container the same doesn't reflect in the host filesystem which in this case is the linux subsystem. Similarly, a file created in the host linux subsystem is not seen in the container's cli when I use the ls command.
I ran this commands to confirm that the folder has been mounted where 44711fc95366 is my container id
docker inspect -f "{{ .Mounts }}" 44711fc95366
This gives an output like so:
[{bind /home/userlab1/my-proj/getting-started/app /usr/src/app true
rprivate}]
If the mount point expressed above is correct, I should be able to create a file or folder in host subsystem on the path /home/userlab1/my-proj/getting-started/app and be able to see it at the /usr/src/app path in the container, correct?
The docker image has been created and run from the linux subsystem command line like so:
docker run -it -v ~/my-proj/getting-started/app:/usr/src/app -p 3001:3000 --name cntr-linux-todo
img-todo:in-linux
While the application runs, the files updated in the container don't reflect on the website that is running from the container, nor does a new file/folder created in the container be seen in the host subsystem and vice versa. What am I missing?
As you are using Windows's version of docker, it cannot see files/folders from WSL.
You can move ~/my-proj into C:\Users\user20358, and mount from there :
-v 'C:\Users\user20358\my-proj\getting-started\app:/usr/src/app'
I am unable to find the location where images and containers are stored in my machine, i checked this and with 'docker info' in Docker Root Dir i have /var/lib/docker , but i'm unable to find this anywhere,
They live under C:\ProgramData\docker
(This is for case of WSL2.)
Docker images are managed by docker's own VM. The path /var/lib/docker given by "docker info" is relative to docker's host file system, not your container's file system. The mount points are different for them. You can view docker's host file system in either of the following ways:
You can mount the host file system to a container directory. Such as,
docker run -v /:/data -it ubuntu /bin/bash
This command runs a shell in Ubuntu docker image, mounting docker's file system to /data directory. There you can find a complete file system under /data, including the ./var/lib/docker. If you want, you can "chroot /data" in the shell prompt to have a better view.
When docker is enabled with your distribution in WSL2, you can always check your containers in your distribution /mnt directory. Docker has mounted everything for you.
/mnt/wsl/docker-desktop-data/data/docker
If you are seasoned enough, you may find the actual location of the virtual disk of all the data in your Windows directory.
C:\Users\your_name\AppData\Local\Docker\wsl\data\
Or probably just for fun:
\\wsl$\Ubuntu\mnt\wsl\docker-desktop-data\data\docker
Unfortunately I haven't tried to dive into them.
I set up a shared folder "tensor" between my Windows machine and the Oracle VM Virtual box called "default". [I run Windows 7, am using Oracle VM Virtual Box Manager, and the Docker Toolbox.]
Then, I open the Docker Toolbox Quickstart terminal, ssh into "default" VM Box, and can successfully mount the tensor folder into it's directory, like so:
I created "hello_world.txt" on my local computer and the file displayed in the VM.
My issue is that I cannot seem to figure out how to have this directory be used when I run the tensorflow image in a container within the default box (also, i am new to this, so please correct me if my terminology here is wrong).
I exit out of the "default" box, and back to my Docker Client terminal. I tried running the following variations of commands (sourced from multiple websites):
docker run -it -p 8888:8888 -p 6006:6006 -v /mnt/tensor:/tensor --name tf gcr.io/tensorflow/tensorflow
This lets me access the Jupyter notebook when i got to http://DEFAULT_IP:8888, but I do not see the "tensor" folder that I expect to see. Instead, the directory is just empty.
However, i assumed in the command above that -v DIRECTORY_VM:DIRECTORY_CONTAINER, so that the first address that I give it is the directory within my default VM, which is to map to a directory inside the container running with the tensor image.
Second trial is that I tried this:
docker run -it -p 8888:8888 -p 6006:6006 -v //c/Users/rebeccak.REBECCAPC/tensor:/tensor --name tf gcr.io/tensorflow/tensorflow
In this case, I provided the path to the "tensor" folder on my local machine instead of the VM Box.
Still no success. Could someone tell me how to do this correctly? Thank you.
Also, when I run "docker inspect CONTAINER_NAME" for one of my attempts, I got this for mounts:
So the "source" folder does not look like the path I specified. Where is this address? Is it on my "default" vm or is it on my daemon client/linux machine?
You did declare a shared folder on VirtualBox, but you still need to properly mount it in your VM.
In your ssh session:
sudo touch /mnt/sda1/var/lib/boot2docker/bootlocal.sh
Add to that file:
mkdir -p /mnt/tensorflow
mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` tensorflow /mnt/tensorflow
Then restart your docker-machine (stop, start)
A -v /mnt/tensor:/tensor should now work.
Check of course that your source folder does exist: that was OP RebeccaK375's issue:
My issue was actually that there was not a "tensor" folder to mount,
Using docker client, is there a way to share a folder in windows with a docker container without having to first share the folder via the Virtual Box VM.
Have understood the need of having a double slash from this and this
Ran the following command from the docker client for windows
docker run -it -v //F/devfolder:/development/windev <imagename> <cmdname>
but when did a ls on /development/windev , it turned out it was empty.
I did not have any problem when I tried mounting the c/Users/username folder via the following command
docker run -it -v //c/Users/username/desktop:/development/windev <image> <command>
and the windev folder listed the contents as I would expect it to be
Tried sharing F/devFolder via Virtualbox GUI and gave full access but still the contents of the folder is not listed.
[I am not using boot2docker but docker-machine]
Is it not possible to share any other folder than the c/Users/ folder? If yes, anything else I need to do to ensure that I can see the contents of the mounted folder?
Not only you have to mount it in your VirtualBox, but you also have to instruct, in your boot2docker TinyCore session that you want that folder visible (once you have done a docker-machine ssh yourMachine):
mount -t vboxsf -o uid=1000,gid=50 your-other-share-name /some/mount/location
I know that you are using docker-machine, and not boot2docker, yet docker-machine is still using a boot2docker.iso VM image based on TinyCore, so this command still applies.
How can I access Docker containers Folder and files from Windows file explorer?
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.
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
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.
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