Git Product home page Git Product logo

git's Introduction

docker-git-alpine

If enjoy, please consider buying me a coffee.

A useful simple git container running in alpine Linux, especially for tiny Linux distro, such as RancherOS, which doesn't have a package manager.

DockerHub Badge

Additional notes about multi-arch images

This feature was added on 23th May 2021.

  1. Version v2.30.2 and 1.0.30 are manually pushed by me with multi-arch image supported
  2. Older version will be not updated as multi-arch images
  3. Newer vesions from now on will be multi-arch images (--platform linux/amd64,linux/arm/v7,linux/arm64/v8,linux/arm/v6,linux/ppc64le,linux/s390x,linux/386)
  4. I don't support other architectures, except amd64, because I have no other environment to do that. If you have any issues with other arch, you need raise PR to fix it.
  5. There would be no difference for docker pull , docker run command with other arch, you can run it as normal. For example, if you need pull image from arm (such as new Mac M1 chip), you can run docker pull alpine/git:v2.30.2 to get the image directly.

Github Repo

https://github.com/alpine-docker/git

CI build logs

https://app.circleci.com/pipelines/github/alpine-docker/git

Docker image tags

https://hub.docker.com/r/alpine/git/tags/

Notes:

New tags with non-root user in image has been created.

alpine/git:<version>-user
alpine/git:user

Its uid and gid in container are 1000

$ docker run -ti --rm --entrypoint=id alpine/git:user
uid=1000(git-user) gid=1000(git-user)

Docker build from feature branch feature/non-root

Usage

docker run -ti --rm -v ${HOME}:/root -v $(pwd):/git alpine/git <git_command>

For example, if you need clone this repository, you can run

docker run -ti --rm -v ${HOME}:/root -v $(pwd):/git alpine/git clone https://github.com/alpine-docker/git.git

Optional usage 1:

To save your type, add this fuction to ~/.bashrc or ~/.profile

$ cat ~/.profile

...

function git () {
    (docker run -ti --rm -v ${HOME}:/root -v $(pwd):/git alpine/git "$@")
}

...

$ source ~/.profile

for example, if you need clone this repository, with the function you just set, you can run it as local command

git clone https://github.com/alpine-docker/git.git

Optional usage 2:

alias git="docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"

NOTES:

  • You need redefine (re-run) the alias, when you switch between different repositories
  • You need run above alias command only under git repository's root directory.

Optional usage 3:

alias git='docker run -ti --rm -u$(id -u):$(id -g) -e HOME=${HOME} -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -v ${HOME}:${HOME} -v $(pwd):/git alpine/git'

NOTES:

  • set uid:gid and provide passwd and group from host
  • run git as the current user instead of root for proper ownership of files
  • can be used at any directory as evaluation of $(pwd) is defered until alias is used

Demo

$ cd application
$ alias git="docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"
$ git clone [email protected]:YOUR_ACCOUNT/YOUR_REPO.git
$ cd YOUR_REPO
$ alias git="docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"
# edit several files
$ git add . 
$ git status
$ git commit -m "test"
$ git push -u origin master

The Protocols

Supports git, http/https and ssh protocols.

Refer: Git on the Server - The Protocols

Automation builds

Set CI to run builds every month.

  • build latest alpine image locally
  • Get the git version from the image
  • use the git's version as image tag as well (v${GIT_VERSION})
  • update latest tag for this image

git's People

Contributors

akadusei avatar bahetiamit avatar barthy1 avatar bhargav3 avatar billamp avatar coreyjewett avatar lerentis avatar ozbillwang avatar pythoncoderas avatar rmie avatar sfllaw avatar stefanscherer avatar stormmore avatar yorch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git's Issues

Docker is sunsetting Free Team organizations

Got mail from Docker Inc, that Docker is sunsetting Free Team organizations

https://web.docker.com/rs/790-SSB-375/images/privatereposfaq.pdf

Our Org alpine is docker free team, if not pay montly, will be closed down by 14th April.

What can we do?

  1. pay monthly fee (US$5), but who should pay?
  2. migrate to other free docker registry, such as github docker registry, gitlab container registry
  3. I share my ethereum address, and waiting for the donation, pay for 1 year first (US$60), then we discuss this case later, if we need formally migrate to other platforms.

The same will be applied to all images in this Org.

One problem with plan of $5, it only supports 5,000 image pulls per day for the whole Org, which is obviously not good enough for this Org.

image

Update git() function

Hello,

This is note an issue, but but a proposal to improve the git() function defined in the optional usage 1.
This function requires to be at the same level of .git directory.

With this update, you could run it in every sub folder :

function git () {
    path=$(pwd)
    while [[ "$path" != "" && ! -e "$path/.git" ]]; do
        path=${path%/*}
    done
    if [ -d "$path" ]; then
        docker run -ti --rm -v ${HOME}:/root -v ${path}:/git alpine/git "$@"
    else
        echo "Error: no .git directory found in parents"
    fi
}


Advice on using with a multistage build?

I was hoping to easily use this image in a multistage build.
Looks like the workdir is /git, so if I were to have a dockerfile like:

FROM alpine/git as git-pull
RUN git clone -b libreoffice-7-1-1 https://git.libreoffice.org/core libreoffice
FROM ubuntu:20.10 as build
RUN mkdir /app
WORKDIR /app
COPY --from=git-pull /git/libreoffice .

I get COPY failed: stat git/libreoffice: file does not exist

Same with COPY --from=git-pull libreoffice .

COPY failed: stat libreoffice: file does not exist

Looking at the Dockerfile for alpine/git I assume it's because /git is used as a volume. I think that means I won't be able to use alpine/git. I guess I would like some confimation

Monthly builds are not running

The latest tag for this image is from 4 months ago, the CI may need to be updated to use the new one from the socat repo.

Can't connect to any url

[/share] # git clone https://github.com/alpine-docker/git.git
Cloning into 'git'...
fatal: unable to access 'https://github.com/alpine-docker/git.git/': Could not resolve host: github.com

[/share] # git clone http://10.96.178.3:13000/DockerConfig/Flare.git
Cloning into 'Flare'...
fatal: unable to access 'http://10.96.178.3:13000/DockerConfig/Flare.git/': Failed to connect to 10.96.178.3 port 13000 after 3070 ms: Couldn't connect to server

10.96.178.3 is local ip of my qnap nas.

Can not clone repository

hey!!

i am trying to use "apline/git" image to clone a repository, however I am getting this error:

Cloning into 'my-repository'...
fatal: unable to access 'https://github.com/my-repository.git/': Could not resolve host: github.com

and it is my dockerfile

FROM alpine/git as clone
WORKDIR /app
RUN git clone https://${TOKEN}@github.com/${ORGANIZATION}/${REPOSITORY}.git

could anybody help me? tks!!

Alpine docker does not support git 2.35.2

Hi there,

We are pulling the latest alpine image and running git commands in CI. However we are running into a fatal: unsafe repository ('...' is owned by someone else). This seems to be a new error due to a security vulnerability in git.

The recommendation is to update to the latest version of git, version 2.35.2. Would it be possible to release a new version of alpine/git so it is possible to upgrade?

Thank you 😃

docker run alpine/git -> push?

Hello,

sorry for the question about usage of this docker image.

How would one issue a "git push" ?

docker run -v {pwd}:/root alpine/git:latest push --dry-run
Fails with error "fatal: not a git repository (or any parent up to mount point /)"

I would be happy to issue a pr and adding this to the readme/docs

Thanks in advance

Host key verification failed when trying to clone in kubernetes

Hey guys.
I'm trying to use this docker image in kubernetes environment.

This is my seetup:

      initContainers:
        - name: repo-init
          image: alpine/git
          args:
            - clone
            - -b "{{BRANCH}}"
            - --single-branch
            - --
            - [email protected]:{{MY_REPO}}
            - /data
          volumeMounts:
            - mountPath: /data
              name: repo-files
            - mountPath: /root/.ssh
              name: ssh-secret-files
              readOnly: true

And I'm getting this error:

Cloning into '/data'...
Host key verification failed.
fatal: Could not read from remote repository.

So, it seems we are missing to generate known_hosts file
Any example of how to accomplish it with this image?

Could not fetch origin when the repo is also dockerized

Hello,

Problem

I'm running a git repository in a docker container. So I have problems to connect from one container to another :

# git remote update
Fetching origin
fatal: Unable to find remote helper for 'http'
error: Could not fetch origin

Solution

alias git="docker run ... --net=host ..."

I'm not sure that adding --net=host for everybody will be better. However, for me, it was the solution.

can i use -u start container without root

I try to use "-u 1000" clone project files.
cause i want create all files with lower privileges, not ROOT privileges.

docker run -u 1000 -i --rm --name git-jobs \
-v /tmp/xxx:/git \
alpine/git:latest clone git@xxx/xxx.git
Cloning into 'xxx'...
No user exists for uid 1000
fatal: Could not read from remote repository.

Git output with ANSI escape codes are not handled (e.g., diff)

By default, git outputs diff output with ANSI escape codes to colorize it. While, this can be disabled, it is convenient. However, with this container the output shows the code rather than actually handling them. I believe this requires some configuration in the image to be able to properly handle the ANSI escape codes (potentially changing the pager).

Add more detailed example for non-root user run

I'm not guru of docker and spent some time to run git commands as non-root.
Here recommend build new new image from original one and define correct user access. It seem bit strange - each developer should create own git image.

In this question on stackoverflow possible workaround.

docker run -it --rm
       --user $(id -u):$(id -g)
       -v $HOME:$HOME:rw
       -v /etc/passwd:/etc/paswd:ro
       -v /etc/group:/etc/group:ro
       -v $PWD:$PWD:rw
       -w $PWD
       alpine/git
       clone ...

And as mentioned torek:

there's no guarantee that these files suffice (some systems use password databases). It's not clear where the "No user exists for ..." message is coming from. It's also not clear whether -v allows files at all—the description in the docker run documentation refers to directories, not files.

I don't know if this solution quite good and corresponds "best practices" of docker.
But if it does - I suggest add this command in readme examples

multi-arch support

I read this document, this is a right direction to deal with multi-arch

https://docs.docker.com/docker-for-mac/multi-arch/

https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/

We should go with simple way, not the hard way with docker manifest

# run one time
docker buildx create --name mybuilder --use

# build multi-arch image with one tag
docker buildx build --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag alpine/git:${version} --push .

With this way, we don't need maintain multiple tags, such as v2.26.2-arm64 and v2.26.2 for same version
and the system itself will know to pull the image for its arch automatically.

I did a sample with alphone/helm:3.5.0-rc.1 for reference
104883378-cb06b100-59b8-11eb-9112-02330ce1dacd

linux/arm64 architecture support

Since you've just implemented multi-arch, would it be possible to add linux/arm64 architecture so that the image can be used on Raspberry Pi?

BUG: Cannot install the `patch` package with the images pushed as "latest" on 2022-08-22

Normally when building with alpine/git we follow by installing the patch package to in turn do some code patching, as follows:

apk add --no-cache patch

However, this is broken for the aarch64 and arm64 targets in the alpine/git:latest builds as tagged 2022-08-22 (being the same day that alpine/git:v2.36.2 got tagged and released).

Oddly, things work just fine with alpine/git:v2.36.2 and with the older alpine/git:v2.36.1. Only this current alpine/git:latest is affected.

(The amd64 target is unaffected.)

.gitconfig is ignored

Hello,

Problem

My .gitconfig file is ignored. So I get this message :

$ git commit -m "my message"            

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got XXXXX)

Solution

alias git=docker run ... -v ~/.gitconfig:/root/.gitconfig ...

However, this works only for those who already have a .gitconfig file in their home.
For me, it worked.

fatal: detected dubious ownership in repository at '/git'

In a local git repo, I enter:

docker run -ti --rm -v ${HOME}:/root -v $(pwd):/git alpine/git status

and it gives me the following error:

docker run -ti --rm -v ${HOME}:/root -v $(pwd):/git alpine/git status
fatal: detected dubious ownership in repository at '/git'
To add an exception for this directory, call:

	git config --global --add safe.directory /git

$(pwd) does not match the root of the git repo, but the place where you evaluate it

docker run -ti --rm -v ${HOME}:/root -v $(pwd):/git alpine/git ...

When you define this as an alias, git will match the repo where you are and never another one. You need to redefine the alias when you change from one repo to another. I suggest that you add a comment about this in README.md where you document the alias (oh, you removed it... I liked it... could you put it back ?)

When you define it in a function, it's better (so keep the function in the .profile in the doc : it's also a good idea).

But in both cases, there is another problem. When pwd is the root of the repository (e.g. there is a directory named .git in your pwd), it works. But if you are in a subdirectory, native git will work, but not your container because /git/.git does not exist in your container. With the alias, it's easy : just define the alias at the right place and it will work. With the function, you need to iterate and find the root directory instead of just using $(pwd).

Another problem (in fact, it's the same, but another way to see it) : let's imagine this git repo :

myrepo/.git
myrepo/README.md
myrepo/subdirectory/somefile

Now add the file for some future commit.

cd myrepo/subdirectory
git add somefile

This should work with native git. But not with your container (because myrepo/subdirectory/somefile is /git/somefile in your container and does not exist - /git/subdirectory/somefile exists). I have no idea how to fix it easily. I think the best is to document the issue and imagine that people are intelligent and will run "git add subdirectory/somefile" when they use your docker container.

  • with the function : you need to "cd myrepo" for all operations
  • with the alias : you can run git from any directory; just be aware that the container think you run it from "myrepo" (this is why I prefer the alias).

Manpages/Help are absent from git commands

git help works fine but that is probably built into Git itself. Running a command like git help add will result in:

warning: failed to exec 'man': No such file or directory
fatal: no man viewer handled the request

How to use it with ssh?

I'm using this image for rancherOS and would like to use ssh for automated deployments but seems like I can't use ssh with this image. Here is the error I see when I try to git clone,

Cloning into 'foo'...
error: cannot run ssh: No such file or directory
fatal: unable to fork

Git pull_request - perl missing in image

During pull_request the error is:

+ git request-pull master ssh://[email protected]:22/gituser/argocd-demo.git fb20231218-07
/usr/libexec/git-core/git-request-pull: line 115: /usr/bin/perl: not found

Looks like perl is missing.

On further investigation is confirmed that Perl is not in the Alpine docker image.

+ which perl
Is Perl on board? ...
-----EOF perl---

This happens both in an older version (2.26) and the newest 2.43.0 version.

Consequence is that the command does not find a version and cannot be executed.

After adding perl to the Dockerfile, everything works fine again. I am not an Dockerfile expert, just added Perl via this example.

what the heck is the latest tag? Git v1 or git v2?

I'm looking at the docker tags and this is really confusing to me. Why do the latest v2 and v1 tags all have different digests?
git

What is latest tag? I would expect it to be the same as either the most recent v1 or v2 tag but the digest is different.

Multiple architectures

Could you create images for architectures other than amd64?

I want to use it both in amd64 and in the Raspberry pi, but it is arm64/v8.

Right now I need to use alpine:latest, and then install git, which is not very complicated, but it could be nicer :)

Git log returns no output when performing revision selection

When executing a revision selection with git on alpine, the output is always nothing. For example
git log master..experiment
always returns nothing. Similarly,
git log ^master experiment
returns nothing. Other git log commands work as expected

This seems to be peculiar to alpine, as I can see this behaviour even in the latest version (Alpine 3.12, git 2.26.2)

sed, cmd_, uname not found while trying to run git-sh-setup for GitSubmodules.

I am using terraform inside a docker image, trying to download the terraform modules git tries to use git-submodules. Here is the error I get.

 /usr/bin/git exited with 127: /usr/libexec/git-core/git-submodule: line 7:
2023-02-02 12:59:17 sed: not found
2023-02-02 12:59:17 /usr/libexec/git-core/git-submodule: /usr/libexec/git-core/git-sh-setup: line
2023-02-02 12:59:17 77: sed: not found
2023-02-02 12:59:17 /usr/libexec/git-core/git-submodule: /usr/libexec/git-core/git-sh-setup: line
2023-02-02 12:59:17 292: uname: not found
2023-02-02 12:59:17 /usr/libexec/git-core/git-submodule: line 611: sed: not found
2023-02-02 12:59:17 /usr/libexec/git-core/git-submodule: line 611: cmd_: not found
2023-02-02 12:59:17 .

does alpine not support the linux commands like sed? Or else I am doing something wrong here.

SSL Internal CA and certificates

Hi There,

I 'm trying to fing a way to use a internal CA to accept a internal SSL certificate and clone from a https internal git repository?

Thanks

curl does not work on latest

Hey,

presumably because of #58 , e.g. curl does not work anymore

❯ docker run --entrypoint sh alpine/git:latest -c 'apk add --no-cache curl;curl -V; curl https://www.google.com' | grep -E "^(fetch|curl|WARNING)"
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
curl 8.0.1 (x86_64-alpine-linux-musl) libcurl/7.83.1 OpenSSL/1.1.1s zlib/1.2.12 brotli/1.0.9 nghttp2/1.47.0
WARNING: curl and libcurl versions do not match. Functionality may be affected.
curl: (48) An unknown option was passed in to libcurl

Is there anyone working on #58 ?

Modernise usage of Docker Hub (link to Dockerfile & automated builds from alpine base image)

Hi,
Would you be open to modernise the usage of Docker hub for this image/repo?

  1. No Dockerfile shown:

Today you can't see any Dockerfile here https://hub.docker.com/r/alpine/git/

This, in combination with that it's not easy to find this GitHub repo from the above page, makes this image seem not-so-trustworthy.

  1. No automated builds

If the base image alpine is updated, this image isn't rebuilt and kept up-to-date.

Would you be open to adding this?

apk has errors when run on arm64

Hi,

We noticed apk add commands fail with an error when run on arm64.

You can reproduce this locally if you have access to an ARM machine:

$ docker run -it --entrypoint=/bin/sh alpine/git
/git # apk --update --no-cache add bash
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
(1/2) Installing readline (8.1.0-r0)
(2/2) Installing bash (5.1.4-r0)
Executing bash-5.1.4-r0.post-install
Executing busybox-1.33.1-r3.trigger
1 error; 27 MiB in 34 packages
/git # echo $?
1

Our workaround is to run apk fix before any other apk command, this seems to repair busybox and ca-certificates:

$ docker run -it --entrypoint=/bin/sh alpine/git
/git # apk fix
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
(1/1) Reinstalling ca-certificates (20191127-r5)
Executing busybox-1.33.1-r3.trigger
Executing ca-certificates-20191127-r5.trigger
OK: 25 MiB in 32 packages
/git # apk --update --no-cache add bash
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
(1/2) Installing readline (8.1.0-r0)
(2/2) Installing bash (5.1.4-r0)
Executing bash-5.1.4-r0.post-install
Executing busybox-1.33.1-r3.trigger
OK: 27 MiB in 34 packages

Our builds use alpine/git:latest and they started failing from Oct 4, 2021, 13:15 UTC. This seems related to the latest merged PR #34.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.