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...
Lets say you want to start a java process inside a container:
Example Dockerfile excerpt:
Example entrypoint.sh excerpt:
Inspired on above, I did this:
When you use an execution list, as in...
...then Docker will execute the given command directly, without involving a shell. Since there is no shell involved, that means:
>
,<
,|
, etccommand1; command2
If you want your
CMD
to expand variables, you need to arrange for a shell. You can do that like this:Or you can use a simple string instead of an execution list, which gets you a result largely identical to the previous example:
If you want to use the value at runtime, set the
ENV
value in theDockerfile
. If you want to use it at build-time, then you should useARG
.Example :
Pass the value in the build command: