lundi 4 octobre 2021

conditional environment definition in Dockerfile

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.

Aucun commentaire:

Enregistrer un commentaire