Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include If else statement in docker file [duplicate]

I want to create docker file with conditional statements. i get parameters from outside ( BUILD_TOOL) . This is the code but i got error while building docker image.

i got this error = dockerfile parse error line 23: unknown instruction: ELSE

RUN if [ "$BUILD_TOOL" = "maven" ] ; then 
    RUN mvn clean install;

#if build tool is gradle
else 
    RUN gradle clean;
fi
like image 767
kavindu Avatar asked Oct 19 '25 14:10

kavindu


1 Answers

Dokerfile itself does not have conditional statements. However you can implement them in shell:

RUN if [ "$BUILD_TOOL" = "maven" ] ; then \
       echo do something; \
    else \
       echo do something else; \
    fi

Just remember to add \ at the end of each line when you have a multi-line command.

like image 121
anemyte Avatar answered Oct 22 '25 05:10

anemyte



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!