docker / docker-py

A Python library for the Docker Engine API
https://docker-py.readthedocs.io/
Apache License 2.0
6.78k stars 1.67k forks source link

Cannot mount binds with windows source #2661

Open nielsgroen opened 4 years ago

nielsgroen commented 4 years ago

I can't seem to mount paths originating from a Windows directory using the docker-py. Mounting paths using docker-compose.yml

docker_client = docker.from_env()
docker_client.containers.run(
  image='ubuntu',
  command='sleep infinity',
  remove=True,
  detach=True,
  mounts=mounts
)

I always seem to get an error:

mounts = [
  Mount(target='/app/data', source=f'/c/', type='volume')
]

400 Client Error: Bad Request ("invalid mount config for type "bind": bind source path does not exist: /c/")

or

mounts = [
  Mount(target='/app/data', source=f'C:/', type='volume')
]

400 Client Error: Bad Request ("invalid mount config for type "bind": invalid mount path: 'C:/' mount path must be absolute")

or

mounts = [
  Mount(target='/app/data', source=f'C:\', type='volume')
]

400 Client Error: Bad Request ("invalid mount config for type "bind": invalid mount path: 'C:/' mount path must be absolute")

same for //c/

using a docker-compose.yml file, everything works no problemo.

I'd not be surprised if there is a mistake somewhere, but I can't seem to figure it out. Any help is much appreciated!

sdolenc commented 4 years ago

I'm encountering the same issue :-/

sdolenc commented 4 years ago

I was able to workaround the bug by using volumes instead of mounts

container = docker_client.containers.run(
    image="blazemeter/taurus",
    command=full_command,
    volumes={
        os.path.realpath(os.getcwd()): {"bind": "/bzt-configs", "mode": "rw"},
        os.path.realpath(TemporaryDirectory().name): {"bind": "/tmp/artifacts", "mode": "rw"},
    },
)

That worked for me when the host machine is Windows or Linux. I'm hoping the underlying bug gets fixed, but I think this may help in the meantime.