Search code examples
gitdockerdockerfilegit-clone

Using Dockerfile RUN to clone a bitbucket repo


I'm trying to clone a bitbucket repository from a dockerfile when running

docker build -t newapi .

So far the Dockerfile it looks like

FROM node:alpine
EXPOSE 3000
RUN git clone https://user:[email protected]/something/api.git

If I run the git clone command by itself in a console it works, already tested it, I'm using it in the form

git clone https://user:[email protected]/something/api.git

And I tried to use the RUN command in many ways which give me different errors:

1.

 RUN git clone https://user:[email protected]/something/api.git

Throws:

Step 6/13 : RUN git clone https://user:[email protected]/something/api.git
---> Running in 9a748f75ff66
/bin/sh: git: not found
The command '/bin/sh -c git clone https://user:[email protected]/something/api.git' returned a non-zero code: 127

2.

RUN ["/bin/bash", "-c", "git clone https://user:[email protected]/something/api.git"]

Throws:

Step 6/13 : RUN ["/bin/bash", "-c", "git clone https://user:[email protected]/something/api.git"]
---> Running in dc7c373071c2
OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown

3.

RUN ["git", "clone", "https://user:[email protected]/something/api.git"]

Throws:

Step 6/13 : RUN ["git", "clone", "https://user:[email protected]/something/api.git"]
 ---> Running in b797b442d1fc
OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"git\": executable file not found in $PATH": unknown

4.

RUN ["/bin/sh", "-c", "git clone https://user:[email protected]/something/api.git"]

Throws:

Step 6/13 : RUN ["/bin/sh", "-c", "git clone https://user:[email protected]/something/api.git"]
 ---> Running in 2fe387a213f3
/bin/sh: git: not found
The command '/bin/sh -c git clone https://user:[email protected]/something/api.git' returned a non-zero code: 127

I don't know what to try anymore, I tried using bash because some people say it works better with git, tried using the raw code which is run with "/bin/sh -c" before it. Is there a way to just execute "git clone..." and avoid the command to be prepended with something? Or what is the way to do what I'm trying to do?

I'm using macOS Mojave 10.14 and Docker Version 18.06.1-ce-mac73 (26764) if that helps


Solution

  • You must install the git package:

    RUN apk add --no-cache git