How can I share a folder between my Windows files and a docker container, by mounting a volume with simple --volume
command using Docker Toolbox on?
I'm using "Docker Quickstart Terminal" and when I try this:
winpty docker run -it --rm --volume /C/Users/myuser:/myuser ubuntu
I have this error:
Invalid value "C:\\Users\\myuser\\:\\myuser" for flag --volume: bad mount mode specified : \myuser See 'docker run --help'.
Following this, I also tried
winpty docker run -it --rm --volume "//C/Users/myuser:/myuser" ubuntu
and got
Invalid value "\\\\C:\\Users\\myuser\\:\\myuser" for flag --volume: \myuser is not an absolute path See 'docker run --help'.
In Dockerfile you can specify only the destination of a volume inside a container. e.g. /usr/src/app . When you run a container, e.g. docker run --volume=/opt:/usr/src/app my_image , you may but do not have to specify its mounting point ( /opt ) on the host machine.
Creating Docker Volumes Another way to create a volume is to use the docker volume create command. If you don't specify a name, docker will give it a name which is a long list of random characters. Otherwise, you can specify a name here. I'm going to call this volume logdata.
Docker Toolbox requires 64-bit Windows 7 (or higher).
View a Data Volume You can use the docker volume ls command to view a list of data volumes. Use the docker volume inspect command to view the data volume details.
This is an improvement of the selected answer because that answer is limited to c:\Users folder. If you want to create a volume using a directory outside of c:\Users this is an extension.
In windows 7, I used docker toolbox. It used Virtual Box.
For example, in my case I have included:
**Name**: c:\dev **Path**: c/dev
Use this command:
$ docker-machine restart
To verify that it worked, following these steps:
Using this command:
$ docker-machine ssh
In my case, I use this command
$ cd /c/dev
You will see something like this:
docker@default:/c/dev$ ls -all total 92 drwxrwxrwx 1 docker staff 4096 Feb 23 14:16 ./ drwxr-xr-x 4 root root 80 Feb 24 09:01 ../ drwxrwxrwx 1 docker staff 4096 Jan 16 09:28 my_folder/
In that case, you will be able to create a volume for that folder.
You can use these commands:
docker create -v /c/dev/:/app/dev --name dev image docker run -d -it --volumes-from dev image
or
docker run -d -it -v /c/dev/:/app/dev image
Both commands work for me. I hope this will be useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With