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
[[email protected] ~]$ docker run -it --rm busybox /bin/sh -c '$(whoami)' /bin/sh: root: not found [[email protected] ~]$ docker run -it --rm busybox /bin/sh -c "$(whoami)" /bin/sh: wbarnwell: not found