Compose: docker-compose fails with invalid volume specification

Created on 30 Mar 2018  ·  20Comments  ·  Source: docker/compose

Description of the issue

docker-compose fails with invalid volume specification

Context information (for bug reports)

Output of "docker-compose version"
PS C:\temp> docker-compose --version
docker-compose version 1.20.1, build 5d8c71b2

Output of "docker version"
PS C:\temp> docker --version
Docker version 18.03.0-ce, build 0520e24

Output of "docker-compose config"
PS C:\temp> docker-compose config
networks:
default:
external: true
name: nat
services:
test:
image: microsoft/windowsservercore
volumes:
- /c/temp:/data:rw
version: '3.6'

Steps to reproduce the issue

PS C:\temp> docker-compose -f c:\temp\docker-compose.yml up --build
Creating temp_test_1 ... error

ERROR: for temp_test_1 Cannot create container for service test: invalid volume specification: '/c/temp:/data:rw'

ERROR: for test Cannot create container for service test: invalid volume specification: '/c/temp:/data:rw'
ERROR: Encountered errors while bringing up the project.

Observed result

Expected to build image with volume mapped.

Expected result

Error: invalid volume specification

Stacktrace / full error message

[18:26:01.536][WindowsDaemon ][Info ] debug: FIXME: Got an API for which error does not match any expected type!!!: invalid volume specification: '/c/temp:/data:rw'
github.com/docker/docker/volume.errInvalidSpec
/go/src/github.com/docker/docker/volume/volume.go:230
github.com/docker/docker/volume.windowsSplitRawSpec
/go/src/github.com/docker/docker/volume/windows_parser.go:87
github.com/docker/docker/volume.(windowsParser).parseMountRaw
/go/src/github.com/docker/docker/volume/windows_parser.go:305
github.com/docker/docker/volume.(
windowsParser).ParseMountRaw
/go/src/github.com/docker/docker/volume/windows_parser.go:301
github.com/docker/docker/daemon.(Daemon).registerMountPoints
/go/src/github.com/docker/docker/daemon/volumes.go:146
github.com/docker/docker/daemon.(
Daemon).setHostConfig
/go/src/github.com/docker/docker/daemon/container.go:215
github.com/docker/docker/daemon.(Daemon).create
/go/src/github.com/docker/docker/daemon/create.go:173
github.com/docker/docker/daemon.(
Daemon).containerCreate
/go/src/github.com/docker/docker/daemon/create.go:75
github.com/docker/docker/daemon.(Daemon).ContainerCreate
/go/src/github.com/docker/docker/daemon/create.go:34
github.com/docker/docker/api/server/router/container.(
containerRouter).postContainersCreate
/go/src/github.com/docker/docker/api/server/router/container/container_routes.go:468
github.com/docker/docker/api/server/router/container.(containerRouter).(github.com/docker/docker/api/server/router/container.postContainersCreate)-fm
/go/src/github.com/docker/docker/api/server/router/container/container.go:47
github.com/docker/docker/api/server/middleware.ExperimentalMiddleware.WrapHandler.func1
/go/src/github.com/docker/docker/api/server/middleware/experimental.go:27
github.com/docker/docker/api/server/middleware.VersionMiddleware.WrapHandler.func1
/go/src/github.com/docker/docker/api/server/middleware/version.go:62
github.com/docker/docker/pkg/authorization.(
Middleware).WrapHandler.func1
/go/src/github.com/docker/docker/pkg/authorization/middleware.go:59
github.com/docker/docker/api/server/middleware.DebugRequestMiddleware.func1
/go/src/github.com/docker/docker/api/server/middleware/debug.go:53
github.com/docker/docker/api/server.(Server).makeHTTPHandler.func1
/go/src/github.com/docker/docker/api/server/server.go:137
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:1918
github.com/docker/docker/vendor/github.com/gorilla/mux.(
Router).ServeHTTP
/go/src/github.com/docker/docker/vendor/github.com/gorilla/mux/mux.go:103
github.com/docker/docker/api/server.(routerSwapper).ServeHTTP
/go/src/github.com/docker/docker/api/server/router_swapper.go:29
net/http.serverHandler.ServeHTTP
/usr/local/go/src/net/http/server.go:2619
net/http.(
conn).serve
/usr/local/go/src/net/http/server.go:1801
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:2337 module=api error_type=*errors.fundamental
```

Additional information

OS version / distribution, docker-compose install method, etc.
Windows 10 Pro
Installed with Docker for Windows

Most helpful comment

Okay, so it seems to work after all, kind of.
I am using Windows containers, and they are bit different in every possible way...

If I create a volume in Dockerfile:

FROM microsoft/nanoserver
SHELL ["powershell.exe", "-Command"]
VOLUME C:/volume

And then use it in docker-compose.yaml:

version: "3"
services:
  localnano:
    build: .
    volumes:
      - testvolume:C:/volume
volumes:
  testvolume:

The files do start to appear in here:

PS> ls (docker volume inspect composer_testvolume --format '{{.Mountpoint}}')

BUT I cannot change the location freely, because of this:
https://github.com/sixeyed/docker-windows-kb/blob/master/1.13/limitations/volumes/driver-opts-not-supported.md

(I think it would really help if someone would re-write the docker-compose tutorial to be Windows compliant, or create a separate "Windows Errata" to list all the tiny differences...)

(And it would be really nice if docker-compose would say something like "the Windows platform does not support volume options" instead of "invalid volume specification"...)

All 20 comments

You probably need to unset COMPOSE_CONVERT_WINDOWS_PATHS in your environment

I don't see COMPOSE_CONVERT_WINDOWS_PATHS set anywhere. I manually set it to 0 and it still fails.

Oh, sorry, did you actually write your mount like this? /c/temp:/data:rw
If so, you need to rewrite it correctly: C:\temp:/data:rw

I have tried just about every possible combination. The volume mapping works correctly when using just docker.

I'm facing the same issue for docker-compose up

any solution to this, facing same issue

Same problem here, OS is Win10 and software is the newest version.

I think this is something that used to work when Docker for Windows had the "Shared Drives" setup screen: d4w-shared-drives
That setup screen does not exist anymore.

Anyhow, "docker run" works fine with volumes. It is the "docker-compose up" that breaks down with "invalid volume specification" error.

Okay, so it seems to work after all, kind of.
I am using Windows containers, and they are bit different in every possible way...

If I create a volume in Dockerfile:

FROM microsoft/nanoserver
SHELL ["powershell.exe", "-Command"]
VOLUME C:/volume

And then use it in docker-compose.yaml:

version: "3"
services:
  localnano:
    build: .
    volumes:
      - testvolume:C:/volume
volumes:
  testvolume:

The files do start to appear in here:

PS> ls (docker volume inspect composer_testvolume --format '{{.Mountpoint}}')

BUT I cannot change the location freely, because of this:
https://github.com/sixeyed/docker-windows-kb/blob/master/1.13/limitations/volumes/driver-opts-not-supported.md

(I think it would really help if someone would re-write the docker-compose tutorial to be Windows compliant, or create a separate "Windows Errata" to list all the tiny differences...)

(And it would be really nice if docker-compose would say something like "the Windows platform does not support volume options" instead of "invalid volume specification"...)

today I encountered the same problem today and it took a long time to solve him.I am loading Docker for Windows.First convert docker to switch to linux containers, then set the volume in the settings, then vs re-add docker support, it will be solved

@usbook That also worked for me, but I have to do it now in a virtual machine (no possibility to switch to Linux containers).
Any ideas?

I'm also facing the same issue. I've written a docker-compose file for wordpress and mysql and this error appears. I only want to use docker as windows containers. Has anybody got some solution for me and wants to share it. Thanks :)

Same problem over here.

Even linux user get the same issue...

+1

When I do this:

$ cat docker-compose.yml
version: '2'
services:
  web:
    ports:
      - 8000:8000
    volumes:
      - ~:/root
      - /:/mnt/fs
    image: coderaiser/cloudcmd
$ docker-compose up
Creating cloud_commander_web_1 ... error

ERROR: for cloud_commander_web_1  Cannot create container for service web: b"invalid volume specification: '/host_mnt/mnt/fs:rw'"

ERROR: for web  Cannot create container for service web: b"invalid volume specification: '/host_mnt/mnt/fs:rw'"
ERROR: Encountered errors while bringing up the project.

The same thing, this works:

$ docker run -t --rm -v ~:/root -v /:/mnt/fs -w=/root -p 8000:8000 coderaiser/cloudcmd
Unable to find image 'coderaiser/cloudcmd:latest' locally
latest: Pulling from coderaiser/cloudcmd
9cc2ad81d40d: Pull complete                                                                                                                                                      e6cb98e32a52: Pull complete                                                                                                                                                      ae1b8d879bad: Pull complete                                                                                                                                                      42cfa3699b05: Pull complete                                                                                                                                                      053cac798c4e: Pull complete                                                                                                                                                      e11ff976ff71: Pull complete                                                                                                                                                      224731f6b161: Pull complete                                                                                                                                                      56ed10abd115: Pull complete                                                                                                                                                      f93be52154ee: Pull complete                                                                                                                                                      a9f043bef697: Pull complete                                                                                                                                                      7f2a997ce950: Pull complete                                                                                                                                                      18e7b16b75e7: Pull complete                                                                                                                                                      6e60a974b71f: Pull complete                                                                                                                                                      Digest: sha256:183404cca02b4e45aa02d96a3c600f9590609d151494f619d4449b8f87ef26e0
Status: Downloaded newer image for coderaiser/cloudcmd:latest
url: http://localhost:8000/

I'm using the latest version of Docker Desktop 2.1.0.6.

It seems if we specify the volume as following:
.\src\Health.Website:C:\src, we need to ensure the environment variable COMPOSE_CONVERT_WINDOWS_PATHS is set to false/0. It works fine for me.

My observation made on mongo:windowsservercore is, that if you use windows container, you need to pass volume sign of container OS

services:
  mongo:
    image: mongo
    hostname: mongo-server
    ports:
      - 27017:27017
    volumes:
      - d:/data:c:/data/db

missing c: was the reason I had invalid volume specification.

Path is probably not converted to unix style. Since 1.9.0, Windows paths are not automatically converted (eg. C:\Users to /c/Users).

Solution: Set COMPOSE_CONVERT_WINDOWS_PATHS environment variable to “true” or “1”.

Had the same issue trying to create linux container on windows machine using docker compose. I am using Docker Desktop.
Realized that my Docker Desktop was set to use Windows containers. Switching it to Linux containers fixed the issue. (Just right click on the Docker Desktop icon on the taskbar).

Hope this helps

Just to throw my hat into the ring -- I came across error and was able to fix it by updating docker to the latest version. Not sure if this is related to the original question but it fixed the error for me and hopefully can for others as well.

It looks like folks are still using this issue as documentation, since Windows paths are somewhat unloved here. I can try to track it down if needed, but the core Docker for Windows team has settled on C: style paths as the canonical path format when you're mounting things from Windows. Of course, ideally, you should run docker from WSL2 and mount from there - it'll be way faster.

Was this page helpful?
0 / 5 - 0 ratings