How to configure as Docker volume a directory on the Desktop in Windows? - windows

I started to work with Docker and I have a problem when I set a volume.
I use windows OS with virtual box.
I would like to create a directory and use the as directory for the volume for a specific image.
The image is Jenkins and I would like to set as volume a directory on the desktop called volume.
I have tried a lot of commands but for the last one I tried on this:
docker run --name MyJenkins1 -v /C/Users/Alessandro/Desktop/volume:/var/jenkins_home -p 9191:8080 -p 40000:50000 jenkins
But I receive the follow result:
'touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?'
I have also tried to set the shared virtual machine directory as follow:
DIRECTORY PATH: C:\Users\Alessandro\Desktop\volume
DIRECTORY NAME: volume
Read_only: no
Auto-mount: yes
Make Permanent: yes
Can somebody help me, please?
Best Regards
Alessandro

Does the user running Docker have permission to write to the "C:\Users\Alessandro\Desktop\volume" directory?
If not, run this from a command line:
set DOCKER_SHARED_DRIVE_USER=...put in the name of the OS user for docker or shared drive if using Docker Desktop...
icacls "C:\Users\Alessandro\Desktop\volume" /grant %DOCKER_SHARED_DRIVE_USER%:(OI)(CI)F

Related

Populating a volume using a container does not work in Docker on Windows

I'm following the instruction on this Docker official page under "Populate a volume using a container" in an attempt to create a new volume populated with existing files in a newly launched container. I ran the following command, expecting the existing files and folders under C:\Data on the container to be available under the volume:
docker run -it --name=test -v C:\Data dataimage/test1:version1
A new volume appears to be created successfully. However, navigating to C:\Data folder on the container shows that it is completely empty. If I run the above command without the -v option instead, then I can see the original files at the same location.
Is this a fully supported feature in Docker on Windows? If so, could someone please shed a light on what I may be doing wrong?
I am using Docker Engine version is v19.03.8. And my host OS is Windows Server 2019.
Try this:
docker run -it --name=test -v '/c/Data:/data' dataimage/test1:version1
That should sync the C:\Data folder on your windows host with the /data folder in the container. If /data isn't the folder name you want in the container, change as needed.

How to access /var/lib/docker in windows 10 docker desktop?

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

Connecting folder in a Docker container with a folder on local machine - Permission Denied

I'm new to docker and am trying to bind mount a folder in my docker container with a folder on my local machine. Using the code below, I was able to create the container with no issue.
docker run -it -v /Users/bdbot/Documents/mount_demo/:/mount_demo nycdsa/linux-toolkits bash
However, when I tried to create a txt file within the container folder, I got this error:
bash: demo.txt: Permission denied
Seeing that it was an access issue, I ran
sudo chmod 777 ../mount_demo
This allowed me to create the file, however when I checked the folder on my local machine it was not there. So the folders are not syncing.
I've also made sure the docker settings "Shared Drives" had the correct credentials. I'm not familiar enough with Docker to know how to trouble shoot further and have not been able to find anything online. I am using Windows, and everything is up to date.
The answer ended up being a really simple fix. The combination of using unix on a windows machine required that I add an additional slash(/) before the folder path. The below fixed this issue for me:
docker run -it -v //Users/bdbot/Documents/mount_demo/:/mount_demo nycdsa/linux-toolkits bash

Docker images and containers location with Windows 10 using hyper-v

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.

Boot2Docker: Can't create directory: Protocol Error

Trying to learn Docker in a windows machine. When I was trying create a new directory inside the shared User folder (/c/Users) by executing sudo mkdir sample but getting an error saying Can't create directory 'sample': Protocol Error.
Any pointers to resolve this issue would be helpful.
VirtualBox does mount automatically C:\users (see VirtualBox Guest Additions), but that does not mean you can create anything directly in C:\Users (not without Administrative privilege, and sudo don't apply here)
You can create anything you want in your own folder: C:\Users\mylogin

Resources