I have a Dockerfile
which currently uses the following:
COPY ./compose/local/django/start.sh /start.sh
RUN sed -i 's/\r//' /start.sh
RUN chmod +x /start.sh
As you can see it copies the file and then makes it executable. I now need to change this depending on a argument provided when I build the image. I have tried using this:
RUN if [ "$arg" = "True" ]; then \
COPY ./compose/local/django/new.sh /new.sh \
RUN sed -i 's/\r//' /new.sh \
RUN chmod +x /new.sh; else \
COPY ./compose/local/django/start.sh /start.sh \
RUN sed -i 's/\r//' /start.sh \
RUN chmod +x /start.sh; fi
But this fails as it appears that I can't run COPY
or RUN
commands inside a conditional statement. It always fails with:
/bin/sh: 1: COPY: not found
or
/bin/sh: 1: RUN: not found
So, I think that the best course of action is to create a separate bash file which does the copies, something like:
#!/usr/bin/env bash
if [ "${arg}" = "True" ]; then
echo "arg = ${arg}"
cp ./compose/local/django/new.sh /new.sh
elif [ "${arg}" = "False" ]; then
echo "arg = ${arg}"
cp ./compose/local/django/start.sh /start.sh
fi
But I am struggling with how to make the copied bash files executable. I know I can do it by running chmod +x
in the command line, but as I am not the only person who is going to be building this, I was hoping that there would be a better solution, something like I was doing previously in the original Dockerfile
script.
Can anyone help me with this? Any help would be much appreciated.