Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get volumes to work with docker-compose in windows #3073

Closed
justechn opened this issue Mar 3, 2016 · 14 comments
Closed

Unable to get volumes to work with docker-compose in windows #3073

justechn opened this issue Mar 3, 2016 · 14 comments

Comments

@justechn
Copy link

justechn commented Mar 3, 2016

I am trying to setup a docker-compose but no matter what I do, I cannot get the volumes to work.

Here is what my docker-compose.yml

version: '2'

services:
    base:
        build: ./base
    ui:
        build: ./ui
        ports:
            - "80:80"
        volumes:
            - ./ui:/src

I have tried several different configurations of volume, but none have worked so far.

If I run my image like this then the volume is mounted correctly

docker run -it -v ui:/src 6d8e034c7fd4 /bin/bash

If I change the docker-compose.yml volume to look like this

volumes:
    - ui:/src

I get an error "Named volume "ui:/src:rw" is used in service "ui" but no declaration was found in the volumes section."

I am using Docker version 1.10.1, build 9e83765 on Windows 7

@dnephin
Copy link

dnephin commented Mar 3, 2016

ui:/src and ./ui:/src mean two different things. The first one is using a named volume, with name ui. The second is a host volume with the path ./ui.

If you're trying to use a named volume, you must declare it in the volumes section (https://docs.docker.com/compose/compose-file/#volume-configuration-reference).

If you're trying to use a host volume, the equivalent with the docker cli is docker run -it -v $PWD/ui:/src ... (at least on osx and linux, I'm not sure what the variable is on windows).

Also note that if you're toolbox, only your home directory and subdirectories are shared with the vm, so the host volume must be under your home directory.

@justechn
Copy link
Author

justechn commented Mar 3, 2016

Thanks for the response.

I am trying to setup a host volume, not a named volume.

If you're trying to use a host volume, the equivalent with the docker cli is docker run -it -v $PWD/ui:/src ... (at least on osx and linux, I'm not sure what the variable is on windows).

This must not be true on windows because the physical path of my code is C:\projects\new_project. ui is a folder under new_project. When I use

docker run -it -v ui:/src 6d8e034c7fd4 /bin/bash

I am able to see my code in the container

@justechn
Copy link
Author

justechn commented Mar 8, 2016

Also note that if you're toolbox, only your home directory and subdirectories are shared with the vm, so the host volume must be under your home directory.

Does this mean with docker compose my source has to be under my user directory?

Because when I use

docker run -it -v ui:/src 6d8e034c7fd4 /bin/bash

I am able to see my code in the container and it is not under my user directory. If they are different, then that could be throwing me off.

@justechn
Copy link
Author

justechn commented Mar 8, 2016

I tried moving my project files into C:\Users\rmclaughlin\projects\powerdialer-ui and I set my volume like this

volumes:
        - /c/users/rmclaughlin/projects/powerdialer-ui/ui:/src

I also tried this

volumes:
        - ./rmclaughlin/projects/powerdialer-ui/ui:/src

but both failed.

@justechn
Copy link
Author

justechn commented Mar 8, 2016

alright, I got it to work. I not only had to move my project under the user directory, but I had to run it from that location also. Now relative paths also work, like this

volumes:
    - ./ui:/src

@justechn justechn closed this as completed Mar 8, 2016
@prene
Copy link

prene commented Nov 17, 2016

As this is currently the first google result for "but no declaration was found in the volumes section", here is a bit more information. In case you actually like to mount an already existing docker volume (not a host directory) using docker-compose, you are dealing with what docker-compose calls an "external volume", which you have to specify in the docker-compose. yml in the following way. So again, let's assume there is already a docker volume with name ui-volume, then this would have to read:

version: '2'
services:
    base:
        build: ./base
    ui:
        build: ./ui
        ports:
            - "80:80"
        volumes:
            - ui-volume:/src
volumes:
    ui-volume:
        external: true

@jamyl
Copy link

jamyl commented Nov 24, 2016

With Bash on Windows, if it can help, I got it to work with this:

  - //c/Users/winuser/code/:/var/www/html

@dmateusp
Copy link

dmateusp commented Dec 29, 2016

@justechn could you describe what you mean by "running it in that location?" I am encountering the same problem as yourself, tried the relative path, having the project under my user files, running docker-compose up from the root of my project. Still getting:
ERROR: for web_db Cannot create container for service web_db: Invalid bind mount spec "C:\\Users\\Daniel\\coding\\project\\database:/var/lib/mysql:rw": Invalid volume specification: 'C:\Users\Daniel\coding\project\database:/var/lib/mysql:rw'

with:

    volumes:
      - ./database/:/var/lib/mysql

@justechn
Copy link
Author

I had to run docker from the project directory instead of giving docker the project path.

Instead of this:

c/users/rmclaughlin/projects/powerdialer-ui/ui/docker run

I did

cd c/users/rmclaughlin/projects/powerdialer-ui/ui
Docker run

@dmateusp
Copy link

And you aren't getting the error message when doing docker-compose up ?

@krissm
Copy link

krissm commented Jan 30, 2017

I'm having the same. I have tried to set the volumes to:
//c/Users/k/dev/angular-seed/:/home/app/angular-seed
c/Users/k/dev/angular-seed:/home/app/angular-seed
.:/home/app/angular-seed
etc

I have also tried adding a .env folder with:
COMPOSE_CONVERT_WINDOWS_PATHS=1
COMPOSE_CONVERT_WINDOWS_PATHS=0

When I do docker-compose up I see everything from:
Recreating angular-seed-start Attaching to angular-seed-start �[36mangular-seed-start |�[0m npm info it worked if it ends with ok �[36mangular-seed-start |�[0m npm info using npm@3.10.3 �[36mangular-seed-start |�[0m npm info using node@v6.6.0 �[36mangular-seed-start |�[0m npm info lifecycle angular-seed@0.0.0~prestart: angular-seed@0.0.0 �[36mangular-seed-start |�[0m npm info lifecycle angular-seed@0.0.0~start: angular-seed@0.0.0 �[36mangular-seed-start |�[0m �[36mangular-seed-start |�[0m > angular-seed@0.0.0 start /home/app/angular-seed �[36mangular-seed-start |�[0m > gulp serve.dev --color �[36mangular-seed-start |�[0m �[36mangular-seed-start |�[0m sh: 1: gulp: not found �[36mangular-seed-start |�[0m �[36mangular-seed-start |�[0m npm info lifecycle angular-seed@0.0.0~start: Failed to exec start script �[36mangular-seed-start |�[0m npm ERR! Linux 4.4.43-boot2docker �[36mangular-seed-start |�[0m npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
to
�[31mERROR�[0m: Named volume "c/Users/k/dev/angular-seed:/home/app/angular-seed:rw" is used in service "angular-seed" but no declaration was found in the volumes section.
to
`Recreating 90b0444c8ee3_90b0444c8ee3_90b0444c8ee3_90b0444c8ee3_angular-seed-start

ERROR: for angular-seed Cannot create container for service angular-seed: invalid bind mount spec "C:\Users\k\dev\angular-seed\dev\angular-seed:/home/app/angular-seed:rw": invalid volume specification: 'C:\Users\k\dev\angular-seed\dev\angular-seed:/home/app/angular-seed:rw'
�[31mERROR�[0m: Encountered errors while bringing up the project.to Recreating 90b0444c8ee3_90b0444c8ee3_90b0444c8ee3_angular-seed-start

ERROR: for angular-seed Cannot create container for service angular-seed: create \c\Users\k\dev\angular-seed: "\c\Users\k\dev\angular-seed" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intented to pass a host directory, use absolute path
�[31mERROR�[0m: Encountered errors while bringing up the project.`

@cmosguy
Copy link

cmosguy commented Mar 30, 2017

@krissm where you able to resolve your issue here?

@ET-CS
Copy link

ET-CS commented Apr 2, 2017

In my case (I was trying to compose from pyCharm) adding .env didn't helped.
for me, adding the COMPOSE_CONVERT_WINDOWS_PATHS=1 as User Environment Variable did the trick.

@brianrichins
Copy link

@krissm I believe the .env should be a file, not a folder. Also, doesn't your second line cancel out your first before it has a chance to affect anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants