docker invalid characters for local volume name

2020-07-09 09:03发布

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

3条回答
爷的心禁止访问
2楼-- · 2020-07-09 09:23

Or simply use double backslash

winpty docker run -it -v C:\\path\\to\\folder:/mount
查看更多
等我变得足够好
3楼-- · 2020-07-09 09:29

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

查看更多
Luminary・发光体
4楼-- · 2020-07-09 09:29

Use git bash and do

export COMPOSE_CONVERT_WINDOWS_PATHS=1

then execute

docker-compose up -d
查看更多
登录 后发表回答