I have a Dockerfile like this:
FROM ubuntu:16.04
:
:
RUN git clone <url>
:
Sometimes, the repo that I want to clone is too large.
So, before running this
git clonecommand, I would like to check whether the repo that I want to clone, exists in the current directory( directory of dockerfile ) and if it does, then I would do aCOPY <repo-name> .instruction instead of theRUN git clone <url>instruction.
I want to achieve something like this:
FROM ubuntu:16.04
:
:
if exists <repo-name>
COPY <repo-name>
else
RUN git clone <url>
:
Is it even possible? If not, are there any tricks that I can do to achieve this?
If-Else isn't a thing in Dockerfiles. You would be better off using a one-liner bash command in your RUN that provided If-Else:
RUN if git clone <repo>; then echo "Exists"; else echo "Error"; fi
Or if the behavior you're after requires more scripting, put it in a script and run it that way to keep all the clutter out of your Dockerfile:
COPY git-script.sh /usr/local/bin
RUN chmod +x /usr/local/bin/git-script.sh && \
bash git-script.sh
Found a similar answer here as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With