compose: docker compose volume mounts not work on Windows

When running docker-compose up, we get this error:

ERROR: for dockerapp  Cannot create container for service dockerapp: Invalid bind mount spec "C:\\Users\\nidal\\dockerapp\\app:/app:rw": Invalid volume specification: 'C:\Users\nidal\dockerapp\app:/app:rw'
ERROR: Encountered errors while bringing up the project.

The docker-compose file is attached below

version: '2'
services:
  dockerapp:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - ./app:/app

  redis:
    image: redis:3.2.0

We get the error both on Docker for Windows and Docker toolbox running on Windows.

$ docker version
Client:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 06:14:34 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 06:14:34 2016
 OS/Arch:      linux/amd64
$ docker-compose version
docker-compose version 1.9.0, build 2585387
docker-py version: 1.10.6
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2h  3 May 2016
$docker-compose --verbose config
compose.config.config.find: Using configuration files: .\docker-compose.yml
networks: {}
services:
  dockerapp:
    build:
      context: C:\Users\nidal\dockerapp
    ports:
    - 5000:5000
    volumes:
    - C:\Users\nidal\dockerapp\app:/app:rw
  redis:
    image: redis:3.2.0
version: '2.0'
volumes: {}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 40

Commits related to this issue

Most upvoted comments

  1. On Command Line: “set COMPOSE_CONVERT_WINDOWS_PATHS=1”;
  2. Restart Docker for Windows;
  3. Go to Docker for Windows settings > Shared Drives > Reset credentials > select drive > Apply;
  4. Reopen Command Line;
  5. Kill the Containers;
  6. Rerun the Containers.

Just type “export COMPOSE_CONVERT_WINDOWS_PATHS=1” and it will work until reboot.

I just discovered the “Reset Credentials…” button in the Shared Drive settings, which solved the issue for me. In my case the volume suddenly stopped working after disabling+enabling Hyper-V. Resetting the credentials for the shared drives fixed it again

using docker toolbox on windows this way i could solve my the issue https://medium.com/@Charles_Stover/fixing-volumes-in-docker-toolbox-4ad5ace0e572

docker-compose.yml:

version: ‘3’ services: web: build: . ports: - “5000:5000” volumes: - //c/var/docker-compose-test:/code redis: image: “redis:alpine”

This settings in the docker-compose file work well:

    volumes:
      - type: bind
        source: ./source_local_directory
        target: c:\target_directory
        bind:
          propagation: cached

If you’re still having issues, please make sure your shared drives are configured properly: https://blogs.msdn.microsoft.com/stevelasker/2016/06/14/configuring-docker-for-windows-volumes/

We made a .env file in same directory as docker-compose.yml file

and added COMPOSE_CONVERT_WINDOWS_PATHS=1

we have also tried this to be true.

but still getting below error.

ABHISHEK@WindowsAbhi MINGW64 ~/Desktop/docker/dockerapp-releases/dockerapp-0.4/dockerapp-0.4 $ docker-compose up dockerapp04_redis_1 is up-to-date Creating dockerapp04_dockerapp_1

ERROR: for dockerapp Cannot create container for service dockerapp: Invalid bind mount spec “C:\Users\ABHISHEK\Desktop\docker\dockerapp-releases\dockerapp-0.4\do ckerapp-0.4\app:/app:rw”: Invalid volume specification: ‘C:\Users\ABHISHEK\Desktop\docker\dockerapp-releases\dockerapp-0.4\dockerapp-0.4\app:/app:rw’ ←[31mERROR←[0m: Encountered errors while bringing up the project.

I have the same issue on Windows 10. I use docker-compose version 1.11.2, build f963d76f and Docker version 17.03.1-ce, build c6d412e and this repo https://github.com/b00giZm/docker-compose-nodejs-examples/tree/master/00-basic-express-generator with correct Dockerfile and docker-compose.yml when i run docker-inspect i get this info: https://www.pastiebin.com/593bc096af354 but when i go inside to container and run ls /src i get this:

root@930bfd8a7df0:/src# ls
node_modules  package.json

i can’t find app directory inside container. But when i run:

PS D:\00-basic-express-generator> docker run --rm -v c:/Users:/data alpine ls /data
Administrator
All Users
Default
Default User 

volumes is working great

Is there any solution how to fix this bug in docker-compose?

Will $PWD also work with COMPOSE_CONVERT_WINDOWS_PATHS=1 ? e.g

drupal:
    driver: local
    driver_opts:
      type: none
      device: $PWD/code/drupal
      o: bind

One and a half months… is there a solution yet?

I was having this issue (at least I think it’s the same issue), but since I wanted to keep Hyper-V off in order to use accelerated emulation for Intel + Android, I couldn’t use the Docker for Windows GUI app and look for those Shared Drives settings that @shin- mentioned, because I was using docker-machine.exe + VirtualBox. So what I had to do in this particular case instead was this: https://forums.docker.com/t/how-to-share-volumes-and-or-drives-using-docker-machine-on-windows-not-beta/20170/2

& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" sharedfolder add default --name "shared" --hostpath "C:/your/shared/folder/" --automount

And then in docker-compose.yml:

volumes:
      - /shared:/some/dir/in/the/container

I think this is more like a workaround and not a full solution, but I hope somebody finds it helpful.

TL;DR: If you’re using VirtualBox and not Docker for Windows, try mounting the drives in VirtualBox with VBoxManage.exe

This did not solve the problem for me. I still run into issues trying to mount files to my docker-compose

It worked for me with COMPOSE_CONVERT_WINDOWS_PATHS=1, but I had to shut down all containers docker-compose stop, not just the one who uses it.

Any reason this was closed? I’ve created a system environment variable and tried the .env file but still no avail.

@rolandwolters You cannot have a file without a filename in Explorer. But you can open a Powershell, navigate to your project directory and type:

mv e.env .env

On Command Line: “set COMPOSE_CONVERT_WINDOWS_PATHS=1”; Restart Docker for Windows; Go to Docker for Windows settings > Shared Drives > Reset credentials > select drive > Apply; Reopen Command Line; Kill the Containers; Rerun the Containers.

  1. On Command Line: “set COMPOSE_CONVERT_WINDOWS_PATHS=1”;
  2. Restart Docker for Windows;
  3. Go to Docker for Windows settings > Shared Drives > Reset credentials > select drive > Apply;
  4. Reopen Command Line;
  5. Kill the Containers;
  6. Rerun the Containers.

You’re the man, it solved the problem, thank you

@gersondinis Sir your a life saver! for me it wasnt the environment variable, it was due to changing windows password, thanks you sir!

Try to change from edge version to stable version on Daemon tab. You should see something like this: https://cdn-enterprise.discourse.org/docker/uploads/default/optimized/2X/d/df575b41215fb89a1f79f6bf8f0864b7366e9955_1_690x312.png

If it doesn’t, try to upgrade/update your Docker for Windows.

@gersondinis there is no option in settings for Shared Drives when Docker CE is running in Windows mode…unless I’m missing something using edge release:

image

@rolandwolters You can bypass the Windows Explorer naming restriction by adding an extra . at the end. So renaming a file and typing “.env.” results in .env, “.gitignore.” becomes .gitignore, etc.