RUN inside a conditional statement in Dockerfile

Use only one ‘RUN’ statement. It’s a best practice as it will reduce the size taken by your image.

This is how you can pass an argument to docker build.

Dockerfile:

...
ARG NEW
COPY ./compose/local/django/new.sh /new.sh
COPY ./compose/local/django/start.sh /start.sh

RUN if [ "$NEW" = "True" ]; then \
    sed -i 's/\r//' /new.sh && \
    chmod +x /new.sh; \
  else \
    sed -i 's/\r//' /start.sh && \
    chmod +x /start.sh; \
  fi

and build it like this

docker build --build-arg NEW="True" .

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)