How can I use a variable inside a Dockerfile CMD?

Inside my Dockerfile:

ENV PROJECTNAME mytestwebsite
CMD ["django-admin", "startproject", "$PROJECTNAME"]

Error:

CommandError: '$PROJECTNAME' is not a valid project name

What is the quickest workaround here? Does Docker have any plan to “fix” or introduce this functionality in later versions of Docker?

NOTE: If I remove the CMD line from the Docker file and then run the Docker container, I am able to manually run Django-admin startproject $PROJECTNAME from inside the container and it will create the project…

5 Answers
5

Leave a Comment