docker / docker-py

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

Backslashes in container command requires double escaping #2406

Open inkychris opened 5 years ago

inkychris commented 5 years ago

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'))

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.

RicardoSaikali commented 2 years ago

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.