compose icon indicating copy to clipboard operation
compose copied to clipboard

docker compose volume mounts not work on Windows

Open jleetutorial opened this issue 9 years ago • 40 comments

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: {}

jleetutorial avatar Jan 07 '17 01:01 jleetutorial

Did you set COMPOSE_CONVERT_WINDOWS_PATHS ?

shin- avatar Jan 07 '17 01:01 shin-

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.

jleetutorial avatar Jan 25 '17 19:01 jleetutorial

Is there a better way to do COMPOSE_CONVERT_WINDOWS_PATHS or any other workaround.

abhisheks2010 avatar Jan 28 '17 22:01 abhisheks2010

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

igordata avatar Feb 02 '17 04:02 igordata

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

BlakeWills avatar Jun 02 '17 14:06 BlakeWills

It's not closed, but that particular issue should be resolved. Make sure your Compose version is up to date and your docker-compose.yml is correct.

shin- avatar Jun 02 '17 16:06 shin-

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?

DavidAdamczyk avatar Jun 10 '17 09:06 DavidAdamczyk

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

HWiese1980 avatar Jul 15 '17 15:07 HWiese1980

Running Docker 17.06.0-ce-win19 (12801) on Windows 10 using Visual Studio 2017 I ran into this thing. I saw the "create e .env file" tip but on Window you cannot have a file with no name?

rolandwolters avatar Jul 17 '17 08:07 rolandwolters

Yes, you can. At least on Windows 10.

HWiese1980 avatar Jul 17 '17 11:07 HWiese1980

@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

riker09 avatar Jul 25 '17 14:07 riker09

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/

shin- avatar Jul 25 '17 23:07 shin-

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.

cre8 avatar Aug 15 '17 14:08 cre8

I've used , in a CMD window, SET COMPOSE_CONVERT_WINDOWS_PATHS=1 and it suddenly starting working. Remember to open a new CMD window.

peteanusergiu avatar Sep 10 '17 08:09 peteanusergiu

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

jaspervandaele avatar Nov 14 '17 16:11 jaspervandaele

@jaspervandaele, thanks a lot, this fixed my issue too. The error message Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type I was facing was so generic that I was wondering what was wrong. As I changed my Windows credentials recently, this is what caused this error. I wished there was something more explicit in case the mounted volume cannot be accessed at all

cvillerm avatar Nov 15 '17 15:11 cvillerm

@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.

brianrichins avatar Dec 07 '17 18:12 brianrichins

@jaspervandaele thanks for that- solved it for me.

aysark avatar Mar 14 '18 18:03 aysark

  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.

gersondinis avatar Apr 08 '18 16:04 gersondinis

@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

wsmelton avatar Apr 24 '18 11:04 wsmelton