Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git install fails in Dockerfile

Tags:

git

docker

I'm trying to pull the repository I'm working on while doing a docker build, so I followed this tutorial so I added in my Dockerfile

# this is our first build stage, it will not persist in the final image FROM ubuntu as intermediate  # install git RUN apt-get update \     apt-get upgrade \     apt-get install git  # add credentials on build RUN mkdir ~/.ssh && ln -s /run/secrets/host_ssh_key ~/.ssh/id_rsa  # make sure your domain is accepted RUN touch /root/.ssh/known_hosts RUN ssh-keyscan github.org >> /root/.ssh/known_hosts  RUN git clone [email protected]:my-repo/myproject.git  FROM ubuntu # copy the repository form the previous image COPY --from=intermediate /your-repo /srv/your-repo 

In my docker-compose.yml I added

secrets:   host_ssh_key:     file: ~/.ssh/id_rsa 

And I'm adding

secrets:   - host_ssh_key 

In one of the service.

Since this is only for my local use (I don't plan on deploying or using this for the production, I just want to test it out) it's fine to use it this way - if it'll work because currently the build fails at the git install stage with error

E: The update command takes no arguments

ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update apt-get upgrade apt-get install git' returned a non-zero code: 100

What am I missing?

like image 854
dingo_d Avatar asked Jun 13 '18 12:06

dingo_d


People also ask

Can we install git in Docker?

Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container.

Does Alpine come with Git?

The problem with the alpine image is that it does not contain GIT (as you can see from the above quote), which is a requirement for NPM to work properly.


1 Answers

You are overanalyzing this. It's just a simple typo. Should be:

RUN apt-get update && \     apt-get upgrade -y && \     apt-get install -y git 

Those are 3 separate commands.

like image 77
Alex Karshin Avatar answered Oct 21 '22 02:10

Alex Karshin