简体   繁体   中英

How to download Git only on Docker?

I want to install only Git in the Linux container, but it wastes a lot of time due to too much "apt-get update" content. Is there any efficient way?

I will recommend to use alpine Linux which is just only 5MB and with git it will become around 20MB .

FROM alpine
RUN apk add --no-cache git
CMD ["git","--version"]

build

docker build -t my_git .

run

docker run -it --rm my_git

If you only want an image with alpine or debian you could use a complete docker image from docker hub for that:

Debian Git: https://hub.docker.com/r/samueldebruyn/debian-git
Alpine Git: https://hub.docker.com/r/alpine/git/

In addition, you can build custom docker images on top of them so you don't have to install git later.

If you just want to install git later in you docker image I would highly recommend to pre install it like Adiii suggested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM