0

I need to set the output of a RUN command to be an environment variable that is available inside my container after it's built:

...

RUN ...
    GO111MODULE=on go get github.com/emersion/hydroxide/cmd/hydroxide && \
    echo "the_password" | hydroxide auth the_username@protonmail.com > bridge_password.txt && \
    BRIDGE_PASSWORD=`sed -n 's/Password: Bridge password: //p' bridge_password.txt` && \
    hydroxide smtp

...

Above, I need $BRIDGE_PASSWORD to be available in my NodeJS project (process.env.BRIDGE_PASSWORD). How can I achieve this?

now_world
  • 940
  • 7
  • 21
  • 56
  • Does the password need to be in the container when it is running (i.e. deployed) or only during the image build? I would advise against putting any passwords into a docker image (_it gets committed to an image layer and if you put that into a repo, it will be available for all to see_) and only pass them into the container at run time with the `-e "BRIDGE_PASSWORD=". – Joel Magnuson Dec 20 '19 at 19:31
  • Well I need the `BRIDGE_PASSWORD` to be available from within the container while its running. And the only way to get the password is to run those commands on build or else I would just pass it in. – now_world Dec 23 '19 at 08:41

1 Answers1

0

You need to:

  1. Declare your env var with the ENV command in your Dockerfile.
  2. Substitute your current RUN with a command in your image entrypoint so that the variable gets set correctly everytime your start a new container and is available to any launched command.
Zeitounator
  • 38,476
  • 7
  • 53
  • 66