0

Trying to pass a variable from a RUN command to a CMD in a docker image. The v variable is passed from value and contains a number, but it does not output when after the container is run. It is declared as as environmental variable and passed to the CMD. Thank you. :).

RUN apk add -- \
    && cd directory \
    && value=$(....)

ARG value

ENV value=$value

CMD [ "sh", "-c", "echo some text $value" ]

To run:

docker run <image>

current

some text

desired

some text 10
2
  • 1
    See the part after the Note in docs.docker.com/engine/reference/builder/#cmd – muru Jan 7 at 11:36
  • I updated the post adding an ARG to store the value on build and then pass that to the ENV for so the $value is available on run time, but value doesn't expand. I updated the CMD as well. When I start the container with -it, I can run the value command andecho is contents. Thank you :). – justaguy Jan 7 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.