0

I have a rather simple issue I cannot figure out. This is the last bit of my Dockerfile:

ARG CLUSTER_NAME
ARG GIT_BRANCH
RUN echo "CLUSTER_NAME: ${CLUSTER_NAME}"
RUN echo "GIT_BRANCH: ${GIT_BRANCH}"
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["infrastructure/ecs/scripts/startup.sh", "user_server", "${CLUSTER_NAME}", "${GIT_BRANCH}"]

And in the startup.sh scripts I get retrieve these args as

SERVICE_NAME="${1}"
CLUSTER_NAME="${2}"
BRANCH_NAME="${3}"

When building the Docker image I can see that ARGS CLUSTER_NAME and GIT_BRANCH are correctly echo'ed, but inside the script, args ${2} and ${3} are empty.

Is there another way to pass args in CMD?

madu
  • 5,232
  • 14
  • 56
  • 96

1 Answers1

1

ARGs are only used at build time, once that's complete they don't stick around as environment variables. I think you'll need to set them to environment variables before you can use them for your script (I hope setting them to the exact same names works).

ARG CLUSTER_NAME
ARG GIT_BRANCH
ENV CLUSTER_NAME=$CLUSTER_NAME
ENV GIT_BRANCH=$GIT_BRANCH
RUN echo "CLUSTER_NAME: ${CLUSTER_NAME}"
RUN echo "GIT_BRANCH: ${GIT_BRANCH}"
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["infrastructure/ecs/scripts/startup.sh", "user_server", "${CLUSTER_NAME}", "${GIT_BRANCH}"]

There's also some variance in how variables are interpreted depending on if CMD is in array format (like yours) or string format. In string format, the command is passed to the default interpreter which will in-turn resolve the environment variables. I'm not sure, but you may also need to change your last line to (or use one of the other techniques in the second link below):

CMD infrastructure/ecs/scripts/startup.sh user_server ${CLUSTER_NAME} ${GIT_BRANCH}

References:

dartagan
  • 36
  • 4