Home > Blockchain >  Does the location of ENV in a Dockerfile matter on the final result?
Does the location of ENV in a Dockerfile matter on the final result?

Time:06-22

Does the location of my ENV in Dockerfile:

ADD rootfs /
CMD ["/usr/sbin/MyApplication -V"]
ENV MY_APP_RUN_IN_TEST=true

matter ? For example in the above example, will MyApplication be run and have access to the MY_APP_RUN_IN_TEST environment variable ?

or do i need to move it above it ?

CodePudding user response:

In your example, MyApplication will have access to the environment variable. The order doesn't matter.

The only way I can think of an ENV statement not being available, is if you have a multi-stage Dockerfile. Then the ENV statement would have to be in the final stage to be included in the image.

For instance, if you have a Dockerfile like this

FROM sdk as build
COPY . .
RUN build my app
ENV MY_ENV_VARIABLE=true

FROM runner
COPY --from=build /build/output .
CMD ["myapp"]

then the environment variable won't be available. If the ENV statement was moved to the last stage of the Dockerfile, then it would be available.

  • Related