Docker Community Forums

Share and learn in the Docker community.

Having trouble mounting volumes using Docker Toolbox on Windows


#1

Hey guys,

I’ve been having a hard time finding a clear and concise guide for mounting volumes using Docker Toolbox.
I’m following the tutorial linked below, and because the tutorial user is working with Docker Desktop for Mac, I’m not having so much luck following along in Windows.

I’m stuck at the part where he’s mounting volumes.
I believe my syntax is correct after searching for other examples and the documentation.

docker container run -d -p 8080:80 -v /D:/Docker:/usr/share/nginx/html --name nginx-website nginx

I don’t know if I’m missing a step or two before this because I keep getting an error response from the daemon.

C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: invalid mode: /usr/share/nginx/html.
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

I actually realize that the colon after C was spliting the string up into another argument. I now tried the following and it seems to have worked.

//D/Docker:/user/share/nginx/html

But when I bash into it on the container, I don’t see any files written to it from the host and when I visit the page it’s gives back a 403 error.

Can I get some help on mounting a volume in Windows, please?

EDIT
Having problems syncing files in mounted volumes

How exactly does Docker Toolbox/VirtualBox treat mounted volumes? If I bash into a container and create a test file, then attempt to mount that directory containing the test file to a directory on my Windows host, wouldn’t I then be able to see the file? I tried such and it didn’t work.

I’m testing different file creation scenarios regarding volume mounting, because the files seen on the host and guest should be exactly the same no matter who mutates them. The Docker container doesn’t seem to be retaining any changes the Windows host makes to the shared directory.

I’ve hit another roadblock in the tutorial video where the instructor is then trying to build a Docker image out of the nginx container where a new index file was added from the host via mounting. The image doesn’t build correctly because the expected result is a page displaying “Hello World” when the newly built image is copied to a new container from the base nginx container where it was created, but is instead displaying the nginx welcome page.


(Garylonbrown) #2

First the volume statement needs to reference a file path on your PC that you’d already created. So, create it first then specify that in your --volume statement. I’ve only done it on Linux so you’ll have to research the correct format for Windows.


(Tekki) #3

The easiest is to cd into the directory and mount the volume with

-v "$(pwd):/usr/share/nginx/html"

Notice that the path starts with usr, not user.

Edit: I realize now that your are on Docker Toolbox, not Desktop. Did you already connect your drive D: to Virtualbox? If not, here is it explained.


#4

Okay, the VM mounting makes sense now. I’m no stranger to VirtualBox. I tend to use it regularly. I just wasn’t sure how hands off Docker Toolbox is from the VIrutalBox Manager GUI since it seems to already do a lot of magic in the background.

The $(pwd) shortcut seems to work too dispite the instructor in the video stating it wouldn’t work on Windows.