Search code examples
pythondockercmddockerfilecommand-substitution

command substitution in docker CMD


Using:

CMD ["$(pipenv --venv)/bin/python3", "main.py", "/root/uploads"]

Causes an error on docker run:

Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"$(pipenv --venv)/bin/python3\\\": stat $(pipenv --venv)/bin/python3: no such file or directory\"\n"

Is there any way to make evaluate command substitutions like $(pipenv --venv)/bin/python3 in the CMD section?


Solution

  • Change it to below

    CMD ["bash", "-c", "$(pipenv --venv)/bin/python3 main.py /root/uploads"]
    

    If that still gives you issue, change $ to $$