Dave Alger
Dave Alger

Reputation: 359

How to mount Virtualbox shared volumes in Docker-Compose

I'm running Docker toolbox on Windows, using Virtualbox to run things.

I can run a container and share a folder on my windows machine which I've called DockerShare and it's been added as a "Shared Folder" to the virtualbox machine.

This command works fine:

docker run -it --name api -p 8802:80 -v /DockerShare/api:/app microsoft/aspnetcore-build:latest

I wanted to do this using a docker-compose script:

version: '2'
services:
  api:
    image: microsoft/aspnetcore-build:latest  
    container_name: api
    ports:
      - "8802:80"
    volumes: 
      - /DockerShare/api:/app 

But this returns an error

ERROR: for api Cannot create container for service api: create \DockerShare\api: "\DockerShare\api" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed

ERROR: Encountered errors while bringing up the project.

I'm running this from the Dockershare folder in the ssh.

Should this work? How should I format the volume string?

Upvotes: 1

Views: 1597

Answers (1)

Dave Alger
Dave Alger

Reputation: 359

Actually it works as it is. However one needs to make sure the environment is set properly. Docker-compose will try to mess around with the address otherwise.

Simply creating a file called ".env" in the same directory as the docker-compose.yml file with the following line:

COMPOSE_CONVERT_WINDOWS_PATHS=0

meant it worked fine.

Upvotes: 1

Related Questions