Home > Software design >  Use docker ARG in Dockerfile CMD
Use docker ARG in Dockerfile CMD

Time:12-18

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

CodePudding user response:

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 in 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"]
  • Related