Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use docker ARG in Dockerfile CMD

how can I use an ARG in the docker cmd command?

FROM python:3.6.8

ARG profile=production
ENV profile ${profile}

ENTRYPOINT [ "export SETTINGS=/opt/${profile}.cfg" ]
CMD [ "python", "-m" ,"acalls_clasiffier"]

This is the error that appears:

exec: "export SETTINGS=/opt/${profile}.cfg": stat export SETTINGS=/opt/${profile}.cfg: no such file or directory: unknown

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are multiple things wrong with this:

  • not separating args as separate array entries with exec syntax
  • trying to use shell expansion of a variable with the exec syntax
  • exec syntax for a shell command (export)

But the simple answer is to define an environment variable either as an ENV the Dockerfile, or preferably as runtime settings in your compose file or kubernetes manifest so you aren’t injecting configuration into the image. Since you’ve only provided the Dockerfile, that looks like:

FROM python:3.6.8

ARG profile=production
ENV profile ${profile}
ENV SETTINGS /opt/${profile}.cfg

CMD [ "python", "-m" ,"acalls_clasiffier"]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading