docker-py
docker-py copied to clipboard
Cannot mount binds with windows source
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!
I'm encountering the same issue :-/
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.
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")