Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

boot2docker - How to use --volume option with Docker Toolbox on Windows?

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'.
question from:https://stackoverflow.com/questions/33126271/how-to-use-volume-option-with-docker-toolbox-on-windows

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

  1. Open virtual box
  2. Select the machine (in my case default).
  3. Right clicked and select settings option
  4. Go to Shared Folders
  5. Include a new machine folder.

For example, in my case I have included:

**Name**: c:dev
**Path**: c/dev
  1. Click and close
  2. Open "Docker Quickstart Terminal" and restart the docker machine.

Use this command:

$ docker-machine restart

To verify that it worked, following these steps:

  1. SSH to the docker machine.

Using this command:

$ docker-machine ssh
  1. Go to the folder that you have shared/mounted.

In my case, I use this command

$ cd /c/dev
  1. Check the user owner of the folder. You could use "ls -all" and verify that the owner will be "docker"

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...