Umair Aamir
Umair Aamir

Reputation: 1644

How to clone git repo using Dockerfile

I am a beginner to Docker. I have written a small Dockerfile to start with. I am not able to clone my repo using following Dockerfile.

FROM mattes/hello-world-nginx
RUN apt-get update && apt-get install -y git
RUN git clone https://github.com/umairnow/LocalizableGenerator.git
VOLUME LocalizableGenerator

I am not sure if I am doing it right or do I have to use WORKDIR. I have also tried following but it doesn't clone the repo.

VOLUME ["/data"]
WORKDIR /LocalizableGenerator

Can anyone help please?

Upvotes: 6

Views: 12090

Answers (3)

farch
farch

Reputation: 492

If you don't want to install git you can use multi stage builds in your Dockerfile,

FROM alpine/git:latest
WORKDIR /clone-workspace
RUN git clone https://github.com/umairnow/LocalizableGenerator.git

FROM mattes/hello-world-nginx
COPY --from=0 /clone-workspace/LocalizableGenerator /path/to/file

Upvotes: 4

Matthieu Moy
Matthieu Moy

Reputation: 16497

Your git clone does work:

$ docker build . -t test
...
Successfully built 5370e446d719
Successfully tagged test:latest
$ docker run -ti test /bin/bash
root@1377e0a4735d:/# cd LocalizableGenerator/
root@1377e0a4735d:/LocalizableGenerator# git log | head
commit 289a77330eefb7abaa90ca61e4226a3c29896e58
Author: Umair Aamir <[email protected]>
Date:   Tue Jan 9 13:04:16 2018 +0100

    Improved get input method. Now user can just drag drop file path or paste file path to generate translation files.

commit e3aa870362b24765095eb80d7aa7910964c010f0
Author: Umair Aamir <[email protected]>
Date:   Tue Jan 9 12:51:57 2018 +0100

root@1377e0a4735d:/LocalizableGenerator#

I don't think you want the VOLUME directive though. VOLUME is used to mount a directory from outside your container to the container itself. Here, you already have the directory within the container.

Upvotes: 3

mapcuk
mapcuk

Reputation: 802

You can clone repo locally (out of docker file) and then use "COPY" or "ADD" instructions to put the code to Docker image. It let you keep image thin without git related software.

Upvotes: 0

Related Questions