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

后端 未结 9 2360
北荒
北荒 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:31

    For those using Virtual Box who prefer command-line approach

    1) Make sure the docker-machine is not running

    Docker Quickstart Terminal:

    docker-machine stop
    

    2) Create the sharing Windows <-> docker-machine

    Windows command prompt:
    (Modify following to fit your scenario. I feed my Apache httpd container from directory synced via Dropbox.)

    set VBOX=D:\Program Files\Oracle\VirtualBox\VBoxManage.exe
    set VM_NAME=default
    set NAME=c/htdocs
    set HOSTPATH=%DROPBOX%\htdocs
    "%VBOX%" sharedfolder add "%VM_NAME%" --name "%NAME%" --hostpath "%HOSTPATH%" --automount
    

    3) Start the docker-machine and mount the volume in a new container

    Docker Quickstart Terminal:
    (Again, I am starting an Apache httpd container, hence that port exposing.)

    docker-machine start
    docker run -d --name my-apache-container-0 -p 80:80 -v /c/htdocs:/usr/local/apache2/htdocs my-apache-image:1.0
    

提交回复
热议问题