docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Cannot mount binds with windows source

Open nielsgroen opened this issue 5 years ago • 3 comments

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!

nielsgroen avatar Sep 02 '20 12:09 nielsgroen

I'm encountering the same issue :-/

sdolenc avatar Sep 23 '20 16:09 sdolenc

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.

sdolenc avatar Sep 25 '20 04:09 sdolenc

same on my end, seems like a huge bug. Still not fixed over 4 years later. kudos! Thanks for the workaround.

mounts = []
  for container_directory in image_defined_volumes:
    base_path = tempfile.mkdtemp()
    os.makedirs(base_path, exist_ok=True)
    mounts.append(Mount(
      target=container_directory,
      source=base_path))

  docker_client.containers.run(
    image=image_name,
    mounts=mounts,
  )

docker.errors.APIError: 400 Client Error for http+docker://localnpipe/v1.47/containers/create: Bad Request ("create C:\Users\xyz\AppData\Local\Temp\tmp5y7hwb_z: "C:\\Users\\xyz\\AppData\\Local\\Temp\\tmp5y7hwb_z" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path")

danielgran avatar Dec 17 '24 17:12 danielgran