Docker exec/run shell command nesting

Your command may not be working as you expected thanks to a common bash gotcha:

docker exec <container> /bin/sh -c "go test $(go list ./... | grep -v '<excluded>')"

The command you are trying to run will perform the expansion of the subshell $() on your host because it is inside double quotes.

This can be solved by single quoting your command as suggested by @cuonglm in the question comments.

docker exec <container> /bin/sh -c 'go test $(go list ./... | grep -v "<excluded>")'

EDIT: A little demo

[wbarnwell@host ~]$ docker run -it --rm busybox /bin/sh -c '$(whoami)'
/bin/sh: root: not found
[wbarnwell@host ~]$ docker run -it --rm busybox /bin/sh -c "$(whoami)"
/bin/sh: wbarnwell: not found

Tags:

Docker

Bash