docker invalid characters for local volume name

时光总嘲笑我的痴心妄想 提交于 2019-12-21 11:29:09

问题


A few days ago, I installed docker on my new laptop. I've used docker for a while and know the basics pretty well. Yet, for some reason I keep bumping into the same problem and I hope someone here can help me.

After installing the Docker Toolbox on my Windows 10 Home laptop, I tried to run some images that I've created using a docker-compose.yml. Since my user directory on windows has my exact name in it (C:/Users/Nick van der Meij) and that name contains spaces, I added an extra shared folder from C:/code to /mnt/code on the Docker Host (this works). I've used this guide to do so

However, when I try to run my docker-compose.yml (included below), I get the following error:

ERROR: for php  Cannot create container for service php: create \mnt\code\basic_php\api: "\\mnt\\code\\basic_php\\api" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed
[31mERROR[0m: Encountered errors while bringing up the project.

As far as I see it, everything seems to be correct according to the official docker docs about volumes. I've spend many hours trying to fix this and tried out multiple "formats" for the volumes tag, yet without any success.

Does anyone know what the problem might be?

Thanks in Advance!

docker-compose.yml

version: '2'
services:
    mysql:
        image: mysql:5.7
        ports:
            - 3306
        volumes:
            - /var/lib/mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: password
            MYSQL_USER: user
            MYSQL_PASSWORD: password
            MYSQL_DATABASE: database
    nginx:
        image: nginx:1.10.2
        ports:
            - 80:80
            - 443:443
        restart: always
        volumes:
            - /mnt/code/basic_php/nginx/conf:/etc/nginx/conf.d
            - /mnt/code/basic_php/api:/code/api
            - /mnt/code/basic_php/nginx:/code/nginx
        links:
            - php
            - site
        depends_on:
            - php
            - site
    php:
        build: php
        expose:
            - 9000
        restart: always
        volumes:
            - /mnt/code/basic_php/php/conf/php.ini:/usr/local/etc/php/conf.d/custom.ini
            - /mnt/code/basic_php/api:/code/api
        links:
            - mysql
    site:
        restart: always
        build: site
        ports:
            - 80
        container_name: site

回答1:


After a few hours searching the web, I finally found what i was looking for. Like Wolfgang Blessen said in the comments below my question, the problem was indeed a Windows Path problem.

If you dont want docker to automatically convert paths windows to unix, you need to add the COMPOSE_CONVERT_WINDOWS_PATHS environment variable with a value of 0 like explained here: link




回答2:


Use git bash and do

export COMPOSE_CONVERT_WINDOWS_PATHS=1

then execute

docker-compose up -d



回答3:


Or simply use double backslash

winpty docker run -it -v C:\\path\\to\\folder:/mount


来源:https://stackoverflow.com/questions/41394822/docker-invalid-characters-for-local-volume-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!