Jyo
Jyo

Reputation: 223

Docker RUN with multiple commands and if conditions

I do not have much knowledge on docker file. Please help me with below requirement.

I am looking for a docker RUN command as below:

RUN set -ex && \
    yum install -y tar gzip && \
    <Other set of commands which includes mkdir, curl, tar>
    rm -vr properties  && \
    if [${arg} == "prod"] then  rm -v conf/args.properties fi 

This is not working and getting error syntax error: unexpected end of file

Upvotes: 1

Views: 2066

Answers (1)

Spirit
Spirit

Reputation: 660

It seems to me, that you have missed one or two ;

If statements in shell need to have a ; after the condition if the then is in the same line.

I have added a second ; after the rm statement before fi.


Your code should look like

RUN set -ex && \
    yum install -y tar gzip && \
    <Other set of commands which includes mkdir, curl, tar>
    rm -vr properties  && \
    if [ ${arg} == "prod" ]; then  rm -v conf/args.properties; fi

Upvotes: 7

Related Questions