Search code examples
dockerdockerfile

Is it possible to pass environment variables from one RUN to another, in Dockerfile?


I'm doing this:

RUN export FOO=hello
RUN env

The second RUN doesn't see the FOO environment variable. Is it a limitation of Docker?

If it is, how do I set PATH in one RUN and make it available in another RUN?


Solution

  • The docker RUN command initializes its own shell when called in a new line. There is no connection between the two RUN commands.

    Bash commands, however, can be combined in a single RUN statement.

    RUN export FOO=hello \
        && env