How to use --volume option with Docker Toolbox on

2020-02-07 15:34发布

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'.

9条回答
冷血范
2楼-- · 2020-02-07 16:16

Simply using double leading slashes worked for me on Windows 7:

docker run --rm -v //c/Users:/data alpine ls /data/

Taken from here: https://github.com/moby/moby/issues/12590

查看更多
老娘就宠你
3楼-- · 2020-02-07 16:17

If you are looking for the solution that will resolve all the Windows issues and make it work on the Windows OS in the same way as on Linux, then see below. I tested this and it works in all cases. I’m showing also how I get it (the steps and thinking process). I've also wrote an article about using Docker and dealing with with docker issues here.

Solution 1: Use VirtualBox (if you think it's not good idea see Solution 2 below)

  • Open VirtualBox (you have it already installed along with the docker tools)
  • Create virtual machine
  • (This is optional, you can skip it and forward ports from the VM) Create second ethernet card - bridged, this way it will receive IP address from your network (it will have IP like docker machine)
  • Install Ubuntu LTS which is older than 1 year
  • Install docker
  • Add shared directories to the virtual machine and automount your project directories (this way you have access to the project directory from Ubuntu) but still can work in Windows
  • Done

Bonus:

  • Everything is working the same way as on Linux
  • Pause/Unpause the dockerized environment whenever you want

Solution 2: Use VirtualBox (this is very similar to the solution 1 but it shows also the thinking process, which might be usefull when solving similar issues)

  • Read that somebody move the folders to /C/Users/Public and that works https://forums.docker.com/t/sharing-a-volume-on-windows-with-docker-toolbox/4953/2
  • Try it, realize that it doesn’t have much sense in your case.
  • Read entire page here https://github.com/docker/toolbox/issues/607 and try all solutions listed on page
  • Find this page (the one you are reading now) and try all the solutions from other comments
  • Find somewhere information that setting COMPOSE_CONVERT_WINDOWS_PATHS=1 environment variable might solve the issue.
  • Stop looking for the solution for few months
  • Go back and check the same links again
  • Cry deeply
  • Feel the enlightenment moment
  • Open VirtualBox (you have it already installed along with the docker tools)
  • Create virtual machine with second ethernet card - bridged, this way it will receive IP address from your network (it will have IP like docker machine)
  • Install Ubuntu LTS which is very recent (not older than few months)
  • Notice that the automounting is not really working and the integration is broken (like clipboard sharing etc.)
  • Delete virtual machine
  • Go out and have a drink
  • Rent expensive car and go with high speed on highway
  • Destroy the car and die
  • Respawn in front of your PC
  • Install Ubuntu LTS which is older than 1 year
  • Try to run docker
  • Notice it’s not installed
  • Install docker by apt-get install docker
  • Install suggested docker.io
  • Try to run docker-compose
  • Notice it’s not installed
  • apt get install docker-compose
  • Try to run your project with docker-compose
  • Notice that it’s old version
  • Check your power level (it should be over 9000)
  • Search how to install latest version of docker and find the official guide https://docs.docker.com/install/linux/docker-ce/ubuntu/
  • Uninstall the current docker-compose and docker.io
  • Install docker using the official guide https://docs.docker.com/install/linux/docker-ce/ubuntu/
  • Add shared directories to the virtual machine and automount your project directories (this way you have access to the project directory from Ubuntu, so you can run any docker command)
  • Done
查看更多
Explosion°爆炸
4楼-- · 2020-02-07 16:19

I solved it!

Add a volume:

docker run -d -v my-named-volume:C:\MyNamedVolume testimage:latest

Mount a host directory:

docker run -d -v C:\Temp\123:C:\My\Shared\Dir testimage:latest

查看更多
Viruses.
5楼-- · 2020-02-07 16:26

This is actually an issue of the project and there are 2 working workarounds:

  1. Creating a data volume:

    docker create -v //c/Users/myuser:/myuser --name data hello-world
    winpty docker run -it --rm --volumes-from data ubuntu
    
  2. SSHing directly in the docker host:

    docker-machine ssh default
    

    And from there doing a classic:

    docker run -it --rm --volume /c/Users/myuser:/myuser ubuntu
    
查看更多
孤傲高冷的网名
6楼-- · 2020-02-07 16:29

share folders virtualBox toolbox and windows 7 and nodejs image container

using... Docker Quickstart Terminal [QST] Windows Explorer [WE]

lets start...

  1. [QST] open Docker Quickstart Terminal

  2. [QST] stop virtual-machine

$ docker-machine stop

  1. [WE] open a windows explorer

  2. [WE] go to the virtualBox installation dir

  3. [WE] open a cmd and execute...

C:\Program Files\Oracle\VirtualBox>VBoxManage sharedfolder add "default" --name "/d/SVN_FOLDERS/X2R2_WP6/nodejs" --hostpath "\?\d:\SVN_FOLDERS\X2R2_WP6\nodejs" --automount

  1. check in the oracle virtual machine, that the new shared folder has appeared

  2. [QST] start virtual-machine

$ docker-machine start

  1. [QST] run container nodejs

docker stop nodejs

docker rm nodejs

docker run -d -it --rm --name nodejs -v /d/SVN_FOLDERS/X2R2_WP6/nodejs:/usr/src/app -w /usr/src/app node2

  1. [QST] open bash to the container

docker exec -i -t nodejs /bin/bash

  1. [QST] execute dir and you will see the shared files
查看更多
在下西门庆
7楼-- · 2020-02-07 16:36

Try this:

  1. Open Docker Quickstart Terminal. If it is already open, run $ cd ~ to make sure you are in Windows user directory.
  2. $ docker run -it -v /$(pwd)/ubuntu:/windows ubuntu

It will work if the error is due to typo. You will get an empty folder named ubuntu in your user directory. You will see this folder with the name windows in your ubuntu container.

查看更多
登录 后发表回答