conditional environment definition in Dockerfile

Published

Simple thing what I want to achieve, but the IF condition in Dockerfile works only for RUN command.

In Dockerfile I have this (shortened version):

ARG MY_ENV
ARG MY_HOST
ENV JAVA_OPTIONS "-Dspring.profiles.active=${MY_ENV}"

What I want to achieve, IF MY_ENV is local, then define:

ENV JAVA_OPTIONS "-Dspring.profiles.active=${MY_ENV} -DMY_HOST=${MY_HOST}"

else leave as it was ENV JAVA_OPTIONS "-Dspring.profiles.active=${MY_ENV}"

The problem is the if/else works only with RUN, as I tried it like:

RUN if [ "$MY_ENV" = "local" ]; then ...

but this is not my case.

Source: Docker Questions

Published
Categorised as docker, dockerfile, if-statement Tagged , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq