6

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?

6
  • Consider reading docs.docker.com/engine/reference/builder Commented Jan 20, 2018 at 15:31
  • I have already read and tried that Commented Jan 20, 2018 at 16:15
  • what do you mean not able to clone my repo ..? what is the error exactly..? Commented Jan 20, 2018 at 16:25
  • Not getting any error. But the folder LocalizableGenerator is empty Commented Jan 20, 2018 at 16:26
  • 1
    its kinda hard to guess without you providing the whole Dockerfile Commented Jan 20, 2018 at 17:03

3 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Can you send documentation that explains more about multi stage builds? Does'nt FROM command download everything from that specific image? So, if i do like FROM UBUNTU, FROM DEBIAN, etc all in the same file my image will turn out huge and probably have a lot of conflicts, no ?
As mentioned in docker multi stage builds official documentation, every FROM instruction start a new stage of the build, here basically you are just copying artifacts from previous stage everything else is left behind and not saved in the final image. (so no your result image will not be huge.
3

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.