Closed MaxEliaserAWS closed 5 months ago
My bad folks. Forgot I had this in my bashrc:
docker()
{
if [ "x$1" = "xkillall" ] ; then
for i in `docker ps | grep " $2 " | sed 's/ .*//'` ; do
`which docker` kill $i
done
else
`which docker` $@
fi
}
Changing to "$@"
with quotes fixes my problem.
Description
If you wish to invoke an executable with an argument containing spaces, shell interpreters allow you to use quotes and-or escaping to prevent the argument being split into multiple arguments, e.g. this always works:
bash -c "echo hi"
However, the Docker client appears to do a second pass on its arguments, splitting arguments containing spaces. Although I can use quotes to prevent my shell from splitting the argument, once my shell has invoked the Docker client with my unitary argument, Docker seems to have a mind of its own and splits it in two anyway.
Reproduce
docker run --rm centos:7 bash -c "echo hi"
I have also tried all the following variants:
and many other variations tried besides.
Expected behavior
Text "hi" should be printed to stdout
docker version
docker info
Additional Info
Just to explain the use case here. I have a container built that already has a
PATH
set, but I want to append another directory to thePATH
on a one-off basis just for one command. Because the host environment does not have access to the container's defaultPATH
value, using--env
argument to Docker client is not a suitable solution. Instead, I am trying to do something like this:docker run --rm my-container /bin/bash -c 'PATH=$PATH:/new/directory comand'
However, there is no way to express this without including a space in my bash command.