How to mount a docker volume while using a windows host?

Mounting a docker volume while being under a windows host, has been a huge pain for me, and i could not get it to work.

Currently i got the following simple Dockerfile:

  • boot2docker fails to start on windows 7
  • Bluemix: service bound to container does not appear in VCAP_SERVICES
  • Docker External File Access Not in /Users/ on OSX
  • boot2docker malformed HTTP status code “/v1.15/containers/json”
  • How can I filter on Windows-based or Linux-based containers within Docker Hub?
  • How can I use a local file on container?
  • FROM php:5-apache
    RUN apt-get update
    

    When i build an image from it, and start a container

    docker build -t phisch:dev .
    docker run phisch:dev
    

    the container starts properly.

    But when i am trying to mount a volume:

    docker run -v /c/Users/phisch/dev/htdocs:/var/www phisch:dev
    

    the following message will be displayed:

    C:\Users\phisch\dev>docker run -v /c/Users/phisch/dev/htdocs:/var/www phisch:dev
    no such file or directory
    docker: Error response from daemon: Container command not found or does not exist..
    

    The /var/www directory definetely exists in the container, trying other directorys does not change the result. Prepending a trailing slash to the host-side directory does not help either. (//c/Users/phisch/dev/htdocs)

    How to mount for example /var/www to C:/Users/phisch/dev/htdocs?

    phisch@DESKTOP-UC1LB9J MINGW64 ~/dev (master)
    $ docker inspect phisch:dev
    [
        {
            "Id": "sha256:73c1533222a905a378f12505ccbd9e9b34cde5a4b34ed008c39e23d5d58a9c91",
            "RepoTags": [
                "dev_web:latest",
                "phisch:dev",
                "phisch:dev3"
            ],
            "RepoDigests": [],
            "Parent": "sha256:d2c4149d86c4dfceaff0e9c4eb5a5d42ca7815f81dd08baad4dc8bda6db2fb10",
            "Comment": "",
            "Created": "2016-02-10T12:16:37.667236134Z",
            "Container": "dad811f51ef3b94d9845d13a0e43ad07ccd5684ea2747b3846accdc71abeb628",
            "ContainerConfig": {
                "Hostname": "e06f5a03fe1f",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "ExposedPorts": {
                    "80/tcp": {}
                },
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "PHP_INI_DIR=/usr/local/etc/php",
                    "PHP_EXTRA_BUILD_DEPS=apache2-dev",
                    "PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2",
                    "GPG_KEYS=0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3",
                    "PHP_VERSION=5.6.18",
                    "PHP_FILENAME=php-5.6.18.tar.xz",
                    "PHP_SHA256=54dd9106c3469bc7028644d72ac140af00655420bbaaf4a742a64e9ed02ec1b0"
                ],
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "apt-get update"
                ],
                "ArgsEscaped": true,
                "Image": "sha256:d2c4149d86c4dfceaff0e9c4eb5a5d42ca7815f81dd08baad4dc8bda6db2fb10",
                "Volumes": null,
                "WorkingDir": "/var/www/html",
                "Entrypoint": null,
                "OnBuild": [],
                "Labels": {}
            },
            "DockerVersion": "1.10.0",
            "Author": "",
            "Config": {
                "Hostname": "e06f5a03fe1f",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "ExposedPorts": {
                    "80/tcp": {}
                },
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "PHP_INI_DIR=/usr/local/etc/php",
                    "PHP_EXTRA_BUILD_DEPS=apache2-dev",
                    "PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2",
                    "GPG_KEYS=0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3",
                    "PHP_VERSION=5.6.18",
                    "PHP_FILENAME=php-5.6.18.tar.xz",
                    "PHP_SHA256=54dd9106c3469bc7028644d72ac140af00655420bbaaf4a742a64e9ed02ec1b0"
                ],
                "Cmd": [
                    "apache2-foreground"
                ],
                "ArgsEscaped": true,
                "Image": "sha256:d2c4149d86c4dfceaff0e9c4eb5a5d42ca7815f81dd08baad4dc8bda6db2fb10",
                "Volumes": null,
                "WorkingDir": "/var/www/html",
                "Entrypoint": null,
                "OnBuild": [],
                "Labels": {}
            },
            "Architecture": "amd64",
            "Os": "linux",
            "Size": 491287784,
            "VirtualSize": 491287784,
            "GraphDriver": {
                "Name": "aufs",
                "Data": null
            }
        }
    ]
    

    Turns out, the container-side directory /var/www needs to be empty, since it had a sub-directory www, docker was not able to use it as a mounting point.

  • How to use the “Remote Systems” view in Eclipse to explore a Docker container file system?
  • Java8 base image has java7 installed docker
  • Unable to build Dockerfile Error: Unable to access jarfile /dev/docker-files/billing/wlp-extended-8.5.5.9.jar
  • Rancher agent can't run on master server?
  • How to serve static content in a Node Express container with Docker?
  • Symfony MongoId Class not found error
  • 3 Solutions collect form web for “How to mount a docker volume while using a windows host?”

    It is possible the / is interpreted as an option by the CMD Windows shell.

    Try first a docker-machine ssh default, in order to open an ssh session in your VM. From there try the docker run again: docker run -v /c/Users/phisch/dev/htdocs:/var/www phisch:dev

    As commented by thaJeztah in issue 18290:

    You could consider using docker-compose; docker-compose allows you to define bind-mounted volumes relative to the location of the docker-compose.yml file.
    Using a docker-compose file allows you to specify all options needed to run your containers in a single file, which makes it ideal for sharing between team members (ie, just run docker-compose up -d will start all containers for the project with the right options).

    This comment mentions a&dding a second /:

    docker run -v //c/Users/phisch/dev/htdocs:`/var/www` phisch:dev
    

    Even in the docker toolbox msys shell session, there are issues (like issue 282)


    After lengthy discussion, the issue was that /var/www had a folder in it.

    Mounting /c/Users/phisch/dev/htdoc onto an empty folder does work, but might not give the expected result, as the default CMD apache2-foreground might still serve its content based on /var/www (which would not have htdocs content if that htdocs is mounted onto another folder).

    if we are talking about docker on windows then we have to take in account the fact that all containers are run on Virtual Box(VB). Before mounting volume to a container we have to be sure that particular folder is available for VB.

    Firstly, define name of current running docker machine, run

    $ docker-machine.exe  active
    default
    

    Secondly, add shared folder to VB

    $ VBoxManage sharedfolder add default --name "some_project" --hostpath D:\Projects\some_project
    

    Thirdly, create folder

    $ docker-machine.exe ssh default 'sudo mkdir --parents /d/projects/some_project'
    

    Fourthly, mount it

    $ docker-machine.exe ssh default 'sudo mount -t vboxsf some_project /d/projects/some_project'
    

    Finally, create container

    $ docker run -v //d/projects/some_project://d/projects/some_project -d some-image_name
    

    I use Docker for Windows with powershell and use $PWD to refer to the current directory when mounting a volume and it works well for me. A couple of examples:

    docker run -p 2368:2368 -v $PWD/ghost:/var/lib/ghost -d ghost
    
    docker run -p 2368:2368 -v $PWD/:/var/lib/ghost -d ghost
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.