I have working docker image that i can run locally by command
docker run --rm -u $(id -u) -v${PWD}:${PWD} -w${PWD} protocbuilder:1.0 [other unimportant args]
And everything works fine. I want use makefile to automate things using that container, so i created make command:
test:
docker run --rm -u $(id -u) -v${PWD}:${PWD} -w${PWD} protocbuilder:1.0 [other unimportant args]
But when I call make test
I'm getting following output:
docker run --rm -u -v/Users/mikolaj/GolandProjects/project:/Users/mikolaj/GolandProjects/project -w/Users/mikolaj/GolandProjects/project protocbuilder:1.0 [other unimportant args]
docker: Error response from daemon: unable to find user -v/Users/mikolaj/GolandProjects/project: no matching entries in passwd file.
make: *** [test] Error 125
I'm not very into makefile things, so I don't understand why makefile fails with that when in standard call of docker run
in console everything works fine. It seems that there is a problem with mapping user into container using -u
, -v
and -w
arguments. Should I do some additional steps in makefile to make this work correctly? Or maybe I need to change something in docker run
command inside makefile?
Thanks in advance
$(...)
is (GNU) make function syntax. If you need to include a literal $
in a shell command for something like command substitution, you need to escape it by doubling the $
test:
docker run --rm -u $$(id -u) ...
# ^^
You could also use the backtick syntax to avoid this escaping issue
test:
docker run --rm -u `id -u` ...
Similarly ${PWD}
gets expanded by make before the command gets run in the shell, but this probably isn't a significant difference.