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

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

    As of August 2016 Docker for windows now uses hyper-v directly instead of virtualbox, so I think it is a little different. First share the drive in settings then use the C: drive letter format, but use forward slashes. For instance I created an H:\t\REDIS directory and was able to see it mounted on /data in the container with this command:

    docker run -it --rm -v h:/t/REDIS:/data redis sh
    

    The same format, using drive letter and a colon then forward slashes for the path separator worked both from windows command prompt and from git bash.

    I found this question googling to find an answer, but I couldn't find anything that worked. Things would seem to work with no errors being thrown, but I just couldn't see the data on the host (or vice-versa). Finally I checked out the settings closely and tried the format they show:

    So first, you have to share the whole drive to the docker vm in settings here, I think that gives the 'docker-machine' vm running in hyper-v access to that drive. Then you have to use the format shown there, which seems to only exist in this one image and in no documentation or questions I could find on the web:

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

提交回复
热议问题