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

后端 未结 9 2311
北荒
北荒 2020-12-12 17:19

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

相关标签:
9条回答
  • 2020-12-12 17:38

    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
    0 讨论(0)
  • 2020-12-12 17:51

    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

    0 讨论(0)
  • 2020-12-12 17:52

    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
    0 讨论(0)
提交回复
热议问题