docker-py
docker-py copied to clipboard
Backslashes in container command requires double escaping
Passing the \ character to the daemon in the containers.create method command argument requires escaping twice, once for the string in Python, and then again for something that requires it internally. From a user perspective, given that the command can be given as a string, I'd expect this string to match one that would be provided to the docker CLI:
$ docker run --rm alpine:3.10 echo char: \
char: \
With the following:
import docker
cli = docker.from_env()
print(cli.containers.run('alpine:3.10', command='echo char: \\').decode('utf-8'))
- Expected output:
char: \ - Actual output:
ValueError: No escaped character - Required command for expected output:
'echo char: \\\\',r'echo char: \\'
I should also note that I first encountered this passing an msbuild command to a Windows container where providing the %5C escape code also seemed to work but not for the alpine container, guessing this was handled by something else.
I have this issue as well. My python script prints a proper path such as C:\abc but when this is passed to client.containers.run as part of a command, the back slashes are removed, if I look at the commands through docker ps -a --no-trunc. What is the deal with this? I will likely have to force double back slash all my directories passed to the command.