问题
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?
回答1:
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 <umair@myworkout.no>
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 <umair@myworkout.no>
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.
回答2:
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.
来源:https://stackoverflow.com/questions/48357742/how-to-clone-git-repo-using-dockerfile