Backslashes in container command requires double escaping
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the containers.create and containers.run command arguments and reproduce the issue using the Python snippet and alpine:3.10. Trace how a string command is processed before reaching the daemon, then verify that a single backslash produces the expected char: \ output without requiring double escaping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100