Volumes not mounting with docker-compose on docker toolbox for windows - windows

I initially configured my docker setup for Docker for Windows. Everything worked great. I'm using docker-compose to define 3 containers, each of which have a volume being mapped from my ./src (path on host) to /src/ (path on container).
I recently found out that the production server might have Windows 10 Home, which doesn't support Docker for Windows. So, my thinking is that I should revert to docker toolbox to be prepared for that scenario.
So I uninstalled Docker for Windows and installed Docker toolbox. I can build my images with docker-compose build just fine, but now when I run docker compose up -d, 2 of my containers immediately crash because the /src/ directory never gets mounted.
I can verify that the volumes are not getting mounted by running docker exec -it ng01 bash and seeing that the volume directory exists but is empty. 2 of my co-workers can reproduce this issue on their windows machines with docker toolbox.
Does anyone know why this is happening, or how to get around it? I've been looking at a bunch of similar SO posts, but the various solutions have gotten me nowhere. I would appreciate some guidance.
Here is my docker-compose file.
I have my source code in src/.
I have my Dockerfiles in docker/
Here is hotloader.Dockerfile.
Here is web.Dockerfile. I don't think they are the issue, but I might as well share them anyways.
Thank you in advance!

Docker Toolbox for Windows works by setting up a VirtualBox VM named default. Running any docker command forwards that command to the VM (Windows Machine → Virtual Machine → Docker).
To mount local Windows folders as Docker volumes, those folders first need to be shared and mounted on the VM that is running Docker.
By default, C:\Users is shared, so mounting volumes from that location will work without any configuration.
So you can either move your project on this already shared location(C:\Users) or you can follow the steps in this document https://headsigned.com/posts/mounting-docker-volumes-with-docker-toolbox-for-windows/
Hope this helps! :)

Related

What is stored in the %USERPROFILE%\AppData\Local\Docker\wsl\distro\ext4.vhdx file for WSL2?

I am using Docker with WSL2 integration on Windows 10 Home.
While following this question to change the location of the docker images I came across this file:
%USERPROFILE%\AppData\Local\Docker\wsl\distro\ext4.vhdx
and couldn't find any explanation online regarding the function of this file.
When you run Docker Desktop WSL2 it'll create 2 vm's, one contains volumes, images, etc., and the other is related to the actual Docker Desktop itself, which is the one you're asking about. It's much smaller.
You can see both of them with: wsl -l -v
The one you're asking about is for the docker-desktop vm.

Mounting a network folder to a Docker container on Windows 10

I'm trying to mount a network folder with a Docker container on Windows 10 with the following syntax. Using UNC paths does not work. I'm running it under Hyper-V and the stable version of Docker.
docker run -v \\some\windows\network\path:/some/local/container
Before I was using Docker Toolbox, and I could map a network share to an internal folder with VirtualBox. I've tried adding the network share as a drive, but it doesn't show up as an available drive under the settings panel.
Currently I'm using mklink to mirror a local folder to the network folder, but I'd like to not depend on this as a solution.
Do this with Windows based containers
Go to Microsoft documentation https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/persistent-storage#smb-mounts.
There you'll find information about how to mount a network drive as a volume in a windows container.
Do this with Linux based containers
Is currently (as of 2019-11-13) not possible. BUT you can use a plugin: https://github.com/ContainX/docker-volume-netshare
I didn't use it, so I have no experience with it. Just found it during my research and wanted to add this as a potential solution.
Recommended solution
While researching on this topic I felt that you should probably mount the drive from within the container. You can pass required credentials either via file or parameters.
Example for credentials as file
You would require to install the package cifs-utils in the container, add
COPY ./.smbcredentials /.smbcredentials
to the Dockerfile and then run the following command after the container is started:
sudo mount -t cifs -o file_mode=0600,dir_mode=0755,credentials=/.smbcredentials //192.168.1.XXX/share /mnt
Potential duplicate
There was another stackoverflow thread on this topic here:
Docker add network drive as volume on windows
The answer provided there (https://stackoverflow.com/a/57510166/12338776) didn't work for me though.

Laradock (container) files on Windows

I installed docker toolbox 1.11.2 and Laradock v.2 cloned from GitHub.
Everything seems to work except the laradock_workspace_1. When is generated it does not create files on the host machine (Windows 7 64-bit). In the docker-compose.yml I have tried playing with the volumes as suggested here
### Laravel Application Code Container ######################
volumes_source:
build: ./volumes/application
volumes:
- ../:/var/www/laravel
If I change the last line to ../.. then run docker-compose up, docker exec -it laradock_workspace_1 ls and I can see that it is traversing the folders on the host machine. I just don't see any files.
My goal here is to make the actual Laravel code external so I can edit them on the host machine and use git.
I can use the Kitematic app to make the changes I want but they seem lost if I do a docker-compose down. (and I get errors about things still being in use.)
I'm new to docker so any help is appreciated.
First, make sure your docker-machine is running. If it is, then follow below:
Open up Virtualbox GUI and right click your docker vm, and select settings, then go to Shared Folders.
Change the c\users to whatever folder your code lies in, like this:
This will mount your desired folder to /c/Users in the docker-machine vm.
After this, change the docker-compose.yml in the laradock folder to this:
### Laravel Application Code Container ######################
volumes_source:
build: ./volumes/application
volumes:
- /c/Users/pomodoro.xyz/code:/var/www/laravel
The logic behind this is, since we are running the docker in a VM, the docker-compose command looks for folder in the VM, not in the windows machines. Thats why we have provided the VM machine path to the docker-compose file.

share windows folder (other than c/Users/) with docker container (using docker windows client)

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.

Accessing Docker container files from Windows

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

Resources