docker-archive / toolbox

The Docker Toolbox
https://docker.com/toolbox
3.22k stars 1.23k forks source link

Can't mount a volume on Windows 7 #607

Open denisvmedia opened 7 years ago

denisvmedia commented 7 years ago

I'm getting this error when I run docker-composer up:

ERROR: for php  Cannot create container for service php: Invalid bind mount spec "D:\\Work\\docker\\project\\sites\\admin:/project_admin:rw": Invalid volume specification: 'D:\Work\docker\project\sites\admin:/project_admin:rw' ←[31mERROR←[0m: Encountered errors while bringing up the project.

Here is what I have in my docker-compose.yml:

        volumes:
            - ../sites/project:/project_admin

This works like charm in native Docker for Windows 10, but with Docker Toolbox on Windows 7 there is a problem. Is it a bug? Or what am I doing wrong?

Lars- commented 7 years ago

I have the same problem with Docker Toolbox on Windows 10.

ERROR: for volumes_source  Cannot create container for service volumes_source: Invalid bind mount spec "C:\\Users\\Lars\\Documents\\Projecten\\smaakgemak:/var/www/laravel:rw": Invalid volume specification: 'C:\Users\Lars\Documents\Projecten\smaakgemak:/var/www/laravel:rw'
ERROR: Encountered errors while bringing up the project.

docker-compose.yml (part that fails):

 volumes_source:
        image: tianon/true
        volumes:
            - ./:/var/www/laravel

EDIT: Downgrading to Docker Toolbox 1.2.0 is a workaround.

t0ngt0n9 commented 7 years ago

I have the same problem on Windows 7 too with the 1.12.5 release.

ERROR: for mysql  Cannot create container for service mysql: 
Invalid bind mount spec "C:\\www\\docker\\mysql:/var/lib/mysql:rw":
Invalid volume specification: 'C:\www\docker\mysql:/var/lib/mysql:rw'
ERROR: Encountered errors while bringing up the project.

Here the line fails in my docker-compose.yml:

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

I tried 1.12.4 release, it's the same problem. I downgraded to 1.12.3 to resolve it.

jayfo commented 7 years ago

Same problem on Windows 10 with Docker Toolbox 1.12.5.

Fixed by downgrading to Docker Toolbox 1.12.3 (did not attempt 1.12.4).

leocavalcante commented 7 years ago

:+1: Win 7 Toolbox 1.12.5

Have any one tried v1.13.0-rc4?

EDIT v1.13.0-rc4 hasn't fixed it either. Had to downgrade to 1.12.3 (1.12.4 also fails).

first087 commented 7 years ago

This bug from docker-compose 1.9.0 (Include in Docker Toolbox 1.12.4+)

Docker Toolbox 1.12.3 include docker-compose 1.8.1. It work!.

aimakun commented 7 years ago

It's from breaking changes in Docker Compose 1.9.0 that need to set additional env variable for Docker Toolbox. https://github.com/docker/compose/releases/tag/1.9.0

leocavalcante commented 7 years ago

Thanks @aimakun! Setting COMPOSE_CONVERT_WINDOWS_PATHS=1 works.

t0ngt0n9 commented 7 years ago

@aimakun thank you! It works now! =)

jaroslavzivny commented 7 years ago

@leocavalcante Where have you gotten the 1.12.3 version? I cannot find it. Thanks!

leocavalcante commented 7 years ago

@jaroslavzivny Setting COMPOSE_CONVERT_WINDOWS_PATHS=1 solves this issue, but if you want to downgrade anyway, you can download old builds navigating through this repo releases: https://github.com/docker/toolbox/releases/tag/v1.12.3

johanchouquet commented 7 years ago

I downgraded to 1.12.3 and 1.8.1 for docker-compose, but i still run into issues : i now have "Invalid bind mount spec "local_path:/var/www/html': invalid mode: /var/www/html. I am on Windows 7, and my volume is set like that:

`volumes:

I tried several things, for the path : with '/', with '//', with only '.:/var/www/html', and more... I tried with or without COMPOSE_CONVERT_WINDOWS_PATHS=1 or 0.

Any other ideas that could help ?

leocavalcante commented 7 years ago

@dargoan You need to "translate" your Win path to a Unix-like: /c/users/jct/code/03-docker

What is happening is that you are using two ":" then Docker guesses as: First part /C is the host Second part /user/jtc... is the container And the optional thirdy part was given as /var/ww/html

But this third part should be the mode, so Docker errors with: invalid mode: /var/www/html

If you are using Git Bash or Docker Quickstart Terminal, then /$PWD should work fine. If you are using Composer then relative path should work just fine as well:

volumes:
  - ./:/var/www/html
johanchouquet commented 7 years ago

Thanks for the quick answer @leocavalcante (amazing!) ! This is true, i read that but forgot. I tried, but now, it tells me 'Cannot create container for service app: The working directory 'C:/Program Files/Git/var/www/html' is invalid. It needs to be an absolute path.

I already had this error message, but I don't see why Docker talks about my Git directory...

leocavalcante commented 7 years ago

You need to put a slash before $PWD, I often run into this issue too :laughing:

docker run -v /$PWD:/var/www/html -p 8000:80 php:apache
johanchouquet commented 7 years ago

Thanks again! Well, for now docker run is OK. I managed to do so. But the problem remains when trying to do : docker-compose run --rm -d -w /var/www/html app composer install with the definitions of volumes such as : //C/users/jct/code/03-docker/:/var/www/html

Now, I'm getting this error message : Cannot create container for service app: The working directory 'C:/Program Files/Git/var/www/html' is invalid. It needs to be an absolute path.

leocavalcante commented 7 years ago

In the docker-compose.yml file you can use relative paths. e.g:

version: '2'
services:
  web:
    image: php:apache
    volumes:
      - ./:/var/www/html
    ports:
      - "8000:80"

For a more concrete example: https://github.com/leocavalcante/siler-todo/blob/master/docker-compose.yml

johanchouquet commented 7 years ago

Well, this is not working neither with relative paths. I'am a Windows 7 user by the way. You're on mac @leocavalcante ? Just tried this : docker-compose run --rm -d app composer install, and it did actually something ! In fact, I didn't set the -w parameter.

Any idea why ?

johanchouquet commented 7 years ago

But one thing is sure: it did run the command i wanted : composer install => no /vendor directory in my current folder.

leocavalcante commented 7 years ago

How is your docker-compose.yml file? Is it at 03-docker folder? Ps. I run Win 7 at work and Win 10 at home, both works nice.

johanchouquet commented 7 years ago

@leocavalcante , my docker-compose file is like that :

version: '2'
services:
  app:
    build:
      context: ./docker/app
      dockerfile: Dockerfile
    image: dargoan/app
    volumes:
     - ./:/var/www/html
    ports:
     - "80:80"
    networks:
     - sdnet
  node:
    build:
      context: ./docker/node
      dockerfile: Dockerfile
    image: dargoan/node
    volumes:
     - ./:/var/www/html
    networks:
     - sdnet
  mysql:
    image: mysql:5.7
    ports:
     - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: "secret"
      MYSQL_DATABASE: "homestead"
      MYSQL_USER: "homestead"
      MYSQL_PASSWORD: "secret"
    volumes:
     - mysqldata:/var/lib/mysql
    networks:
     - sdnet
  redis:
    image: redis:alpine
    volumes:
     - redisdata:/data
    networks:
     - sdnet
networks:
  sdnet:
    driver: "bridge"
volumes:
  mysqldata:
    driver: "local"
  redisdata:
    driver: "local"

So, as a recap :

What do you think ? Is this related to an issue with the -w param ?

leocavalcante commented 7 years ago

It seams that Docker is using path at -w as a relative folder. Try double slashes:

docker-compose run --rm -d -w //var/www/html app composer install
johanchouquet commented 7 years ago

Ok, it seems better now, but nonetheless, it doesn't the command composer install. But it doesn't complain anymore. So, still no /vendor directory, and no Laravel application working in Docker on Win 7 :(.

But, when I added --verbose param to docker-compose command, i obtained this :

compose.config.config.find: Using configuration files: .\docker-compose.yml
docker.auth.auth.find_config_file: Trying paths: ['C:\\Users\\jct\\.docker\\config.json', 'C:\\Users\\jct\\.dockercfg']
docker.auth.auth.find_config_file: Found file at path: C:\Users\jct\.docker\config.json
docker.auth.auth.load_config: Found 'auths' section
docker.auth.auth.parse_auth: Found entry (registry=u'https://index.docker.io/v1/', username=u'dargoan')
compose.cli.command.get_client: docker-compose version 1.8.1, build 004ddae
docker-py version: 1.10.3
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2h  3 May 2016
compose.cli.command.get_client: Docker base_url: https://192.168.99.100:2376
compose.cli.command.get_client: Docker version: KernelVersion=4.4.27-boot2docker, Os=linux, BuildTime=2016-10-26T23:26:11.105168198+00:00, ApiVersion=1.24, Version=1.12.3, GitCommi
t=6b644ec, Arch=amd64, GoVersion=go1.6.3
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- (u'beregistration_sdnet')
compose.network.ensure: Creating network "beregistration_sdnet" with driver "bridge"
compose.cli.verbose_proxy.proxy_callable: docker create_network <- (ipam=None, driver='bridge', options=None, name=u'beregistration_sdnet')
compose.cli.verbose_proxy.proxy_callable: docker create_network -> {u'Id': u'b8c255a89dac95d9041cf8f274ea8ec1f376e7ee6e6d206c5b50c769ddacb7b4',
 u'Warning': u''}
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume <- (u'beregistration_redisdata')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume -> {u'Driver': u'local',
 u'Labels': None,
 u'Mountpoint': u'/mnt/sda1/var/lib/docker/volumes/beregistration_redisdata/_data',
 u'Name': u'beregistration_redisdata',
 u'Scope': u'local'}
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume <- (u'beregistration_redisdata')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume -> {u'Driver': u'local',
 u'Labels': None,
 u'Mountpoint': u'/mnt/sda1/var/lib/docker/volumes/beregistration_redisdata/_data',
 u'Name': u'beregistration_redisdata',
 u'Scope': u'local'}
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume <- (u'beregistration_mysqldata')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume -> {u'Driver': u'local',
 u'Labels': None,
 u'Mountpoint': u'/mnt/sda1/var/lib/docker/volumes/beregistration_mysqldata/_data',
 u'Name': u'beregistration_mysqldata',
 u'Scope': u'local'}
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume <- (u'beregistration_mysqldata')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume -> {u'Driver': u'local',
 u'Labels': None,
 u'Mountpoint': u'/mnt/sda1/var/lib/docker/volumes/beregistration_mysqldata/_data',
 u'Name': u'beregistration_mysqldata',
 u'Scope': u'local'}
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('dargoan/app')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {u'Architecture': u'amd64',
 u'Author': u'Johan Chouquet',
 u'Comment': u'',
 u'Config': {u'ArgsEscaped': True,
             u'AttachStderr': False,
             u'AttachStdin': False,
             u'AttachStdout': False,
             u'Cmd': [u'/usr/bin/supervisord'],
             u'Domainname': u'',
             u'Entrypoint': None,
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={u'label': [u'com.docker.compose.project=beregistration', u'com.docker.compose.service=app', u'com
.docker.compose.oneoff=True']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={u'label': [u'com.docker.compose.project=beregistration', u'com.docker.compose.service=app', u'co
m.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker create_host_config <- (cap_add=None, links=[], devices=None, pid_mode=None, log_config={'Type': u'', 'Config': {}}, cpu_quota=None,
 read_only=None, dns=None, volumes_from=[], port_bindings={}, security_opt=None, extra_hosts=None, cgroup_parent=None, network_mode=u'beregistration_sdnet', shm_size=None, tmpfs=No
ne, memswap_limit=None, restart_policy=None, dns_search=None, privileged=False, binds=[u'/c/users/jct/code/03-docker/shippingdocker/be-registration/be-registration:/var/www/html:rw
'], ipc_mode=None, mem_limit=None, cap_drop=None, ulimits=None)
compose.cli.verbose_proxy.proxy_callable: docker create_host_config -> {'Binds': [u'/c/users/jct/code/03-docker/shippingdocker/be-registration/be-registration:/var/www/html:rw'],
 'Links': [],
 'LogConfig': {'Config': {}, 'Type': u''},
 'NetworkMode': u'beregistration_sdnet',
 'PortBindings': {},
 'VolumesFrom': []}
compose.cli.verbose_proxy.proxy_callable: docker create_container <- (tty=False, labels={u'com.docker.compose.version': u'1.8.1', u'com.docker.compose.container-number': '1', u'com
.docker.compose.service': u'app', u'com.docker.compose.project': u'beregistration', u'com.docker.compose.oneoff': u'True'}, name=u'beregistration_app_run_1', image='dargoan/a
pp', stdin_open=False, host_config={'NetworkMode': u'beregistration_sdnet', 'Links': [], 'PortBindings': {}, 'Binds': [u'/c/users/jct/code/03-docker/shippingdocker/be-registration/
be-registration:/var/www/html:rw'], 'LogConfig': {'Type': u'', 'Config': {}}, 'VolumesFrom': []}, environment=[], working_dir='//var/www/html', command=['composer', 'install'], vol
umes={u'/var/www/html': {}}, detach=True, ports=[], networking_config={u'EndpointsConfig': {u'beregistration_sdnet': {u'IPAMConfig': {}, u'Aliases': ['app']}}})
compose.cli.verbose_proxy.proxy_callable: docker create_container -> {u'Id': u'0df53c5ae127ae0b9cc5deeb34c54b028a0a464e7288e0119131624f66ba0a09',
 u'Warnings': None}
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'0df53c5ae127ae0b9cc5deeb34c54b028a0a464e7288e0119131624f66ba0a09')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'',
 u'Args': [u'install'],
 u'Config': {u'AttachStderr': False,
             u'AttachStdin': False,
             u'AttachStdout': False,
             u'Cmd': [u'composer', u'install'],
             u'Domainname': u'',
             u'Entrypoint': None,
             u'Env': [u'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
                      u'LANG=en_US.UTF-8',
...
compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network <- (u'0df53c5ae127ae0b9cc5deeb34c54b028a0a464e7288e0119131624f66ba0a09', u'beregistration_sdnet')

compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network -> None
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network <- (u'0df53c5ae127ae0b9cc5deeb34c54b028a0a464e7288e0119131624f66ba0a09', u'beregistration_sdnet', ipv4
_address=None, ipv6_address=None, links=[], aliases=[])
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network -> None
compose.cli.verbose_proxy.proxy_callable: docker start <- (u'0df53c5ae127ae0b9cc5deeb34c54b028a0a464e7288e0119131624f66ba0a09')
compose.cli.verbose_proxy.proxy_callable: docker start -> None

It seems that the command composer install is understood by Docker as two separate commands, as shown in the array : u'Cmd': [u'composer', u'install'],

So, I tried to run docker-compose run --rm -d -w //var/www/html app 'composer install', but this time i finished by having this error: ←[31mERROR←[0m: compose.cli.main.main: Cannot start service app: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\ \"composer install\\\": executable file not found in $PATH\"\n"

leocavalcante commented 7 years ago

I think it is how Docker reads commands, it splits into space-separated parts since between quotes it thinks that composer install is a full filename.

I start to guess it isn't a Docker related problem 🤔 Are you able to run composer install in your local machine? Or try to bash into app container first docker exec -it yourpath_app bash then inside it composer install.

johanchouquet commented 7 years ago

Well, thank you for all these advices. It appears that I have composer installed on my local machine, so composer install works perfectly.

The command docker exec -it my_path container_id bash is also working fine. I can login into my docker container. There, if I type composer, I can see the help of composer, as /usr/bin is in the PATH of the Linux container.

But when I go to /var/www/html though, there is only one index html file, for nginx.

BUT: when I type docker run --rm -it -p 80:80 -v /$(pwd):/var/www/html dargoan/app, it launches the CMD from the App Docker file (supervisord). This container appears in Kitematic. And there, I can do "EXEC" at the top, which launches a Powershell. There, when i go to /var/www/html, i can see the mount of my local drive (so, going through Kitematic and Docker run, it's OK), with all my Laravel files. I also can type composer and it gives me the help. So, doing, from there: composer install just works ! It starts downloading everything needed. Also, going to the IP address of the container shows the view of the application, at last :)!

The thing is : i can't manage to obtain the same going through docker-compose command.

leocavalcante commented 7 years ago

Hm, got it. It seams that you got it working, but maybe you could try docker-compose exec instead of run.

johanchouquet commented 7 years ago

I'll try that indeed. But it seems to me that there might be a small bug in the docker-compose run command, in relation to mount functionality, because with docker run command, I could mount my volume at the right place which is the main issue that I encountered + set my working directory to /var/www/html (on Win 7, it was -w //var/www/html which is not very intuitive).

The consequence of that is that i can't manage my services the way I wanted to, through the docker-compose.yml file.

Thanks a lot @leocavalcante for your help, it helped me get this to work !

leocavalcante commented 7 years ago

Np, glad to help :smile:

caztial commented 7 years ago

i had the same issue but putting lower case and back slash solved it

-v c:/wamp/www/mpesa:/home/src

johanchouquet commented 7 years ago

I ultimately resolved my initial problem. With docker-compose run, it didn't work. So, i only used docker-compose up and docker-compose down commands. I looked at the result of the app in Kinematic. At first (with the difficulties i encountered), it didn't work, because of my volume issue. But, when i set manually the volume, it worked right away. So, i ended up inspecting my configuration when KO vs OK, and it showed some small surprises.

I had to put: /c/Users/jct/code/03-docker/shippingdocker/be-registration/be-registration:/var/www/html:rw

instead of: /c/users/jct/code/03-docker/shippingdocker/be-registration/be-registration://var/www/html or c:/users/jct/code/03-docker/shippingdocker/be-registration/be-registration://var/www/html

which doesn't work for Win 7.

So, quick differences:

With these minor changes, it worked, at last..!

thuynguyena1 commented 7 years ago

I had to put: /c/Users/jct/code/03-docker/shippingdocker/be-registration/be-registration:/var/www/html:rw ==> it worked compose 1.9.0 ***NOTE: c:/Users ==> /c/Users ==>worked for me Thanks

anshul-mohil commented 7 years ago

Problem: ERROR: for jenkins Cannot create container for service jenkins: invalid volume spec "path...\jenkins": invalid volume specification: '....\jenkins': invalid mount config for type "volume": invalid mount path: 'somePath...\jenkins' mount path must be absolute ERROR: Encountered errors while bringing up the project. Solution: docker windows toolkit creates a virtual machine on which it host docker engine and its containers. So in order to create a volume you need to give the path available on the virtual machine not on host windows machine. so go to the vm and create path which you want to pass in docker-compose.yml file.

ghost commented 7 years ago

@johanchouquet thanks! Your solution saved me

LoulG commented 6 years ago

From a Windows 10 host and Windows containers, the working volumes specification format that works for me: c:\DATA:c:\data without setting COMPOSE_CONVERT_WINDOWS_PATHS=1 Notice the lower case drive letter

ggajos commented 5 years ago

Dear stranger. If you end up here (as I did multiple times). There is another way of using Docker on Windows.