SRC SRC - 8 months ago 43
Linux Question

libgit2 alpine linux docker error

Ok, This is above my understanding. I have really no idea what exactly is wrong here but something is. I am on the verge of breaking by banging my head on the wall and yet nothing came up. Can any kind soul please help me.

This is my Dockerfile -

FROM golang:1.7-alpine
RUN echo >> /etc/apk/repositories
RUN apk update && apk upgrade && apk add --no-cache bash git openssh alpine-sdk libgit2

RUN pkg-config --print-errors --exists libgit2

I have wrote it with advice from here - How do I install libgit2 on Alipne linux

And this is the end result -

Sending build context to Docker daemon 513 kB
Step 1 : FROM golang:1.7-alpine
---> 161e259af05d
Step 2 : RUN echo >> /etc/apk/repositories
---> Running in 428c62a1fc94
---> 80a4e0dca9d7
Removing intermediate container 428c62a1fc94
Step 3 : RUN apk update && apk upgrade && apk add --no-cache bash git openssh alpine-sdk libgit2
---> Running in 7876608fa4e7
v3.4.4-9-g07aa589 []
v3.4.4-1-g77d84e1 []
v3.4.0-4072-g7fdcbdd []
OK: 7381 distinct packages available
(1/2) Upgrading libcrypto1.0 (1.0.2i-r0 -> 1.0.2j-r0)
(2/2) Upgrading libssl1.0 (1.0.2i-r0 -> 1.0.2j-r0)
Executing busybox-1.24.2-r11.trigger
OK: 5 MiB in 12 packages
(1/63) Installing fakeroot (1.20.2-r3)
(2/63) Installing sudo (1.8.16-r0)
(3/63) Installing libcap (2.25-r0)
(4/63) Installing pax-utils (1.1.6-r0)
(5/63) Installing openssl (1.0.2j-r0)
(6/63) Installing libattr (2.4.47-r4)
(7/63) Installing attr (2.4.47-r4)
(8/63) Installing tar (1.29-r0)
(9/63) Installing pkgconf (0.9.12-r0)
(10/63) Installing patch (2.7.5-r1)
(11/63) Installing libssh2 (1.7.0-r0)
(12/63) Installing libcurl (7.50.3-r0)
(13/63) Installing curl (7.50.3-r0)
(14/63) Installing abuild (2.27.1-r1)
Executing abuild-2.27.1-r1.pre-install
(15/63) Installing binutils-libs (2.26-r0)
(16/63) Installing binutils (2.26-r0)
(17/63) Installing gmp (6.1.0-r0)
(18/63) Installing isl (0.14.1-r0)
(19/63) Installing libgomp (5.3.0-r0)
(20/63) Installing libatomic (5.3.0-r0)
(21/63) Installing libgcc (5.3.0-r0)
(22/63) Installing pkgconfig (0.25-r1)
(23/63) Installing mpfr3 (3.1.2-r0)
(24/63) Installing mpc1 (1.0.3-r0)
(25/63) Installing libstdc++ (5.3.0-r0)
(26/63) Installing gcc (5.3.0-r0)
(27/63) Installing make (4.1-r1)
(28/63) Installing musl-dev (1.1.14-r12)
(29/63) Installing libc-dev (0.7-r0)
(30/63) Installing fortify-headers (0.8-r0)
(31/63) Installing g++ (5.3.0-r0)
(32/63) Installing build-base (0.4-r1)
(33/63) Installing expat (2.1.1-r1)
(34/63) Installing pcre (8.38-r1)
(35/63) Installing git (2.8.3-r0)
(36/63) Installing xz-libs (5.2.2-r1)
(37/63) Installing lzo (2.09-r1)
(38/63) Installing squashfs-tools (4.3-r2)
(39/63) Installing libmagic (5.27-r0)
(40/63) Installing file (5.27-r0)
(41/63) Installing bzip2 (1.0.6-r5)
(42/63) Installing libbz2 (1.0.6-r5)
(43/63) Installing cdrkit (1.1.11-r2)
(44/63) Installing acct (6.6.2-r0)
(45/63) Installing lddtree (1.25-r2)
(46/63) Installing libuuid (2.28-r3)
(47/63) Installing libblkid (2.28-r3)
(48/63) Installing device-mapper (2.02.154-r0)
(49/63) Installing cryptsetup-libs (1.7.1-r0)
(50/63) Installing kmod (22-r0)
(51/63) Installing mkinitfs (3.0.5-r1)
(52/63) Installing mtools (4.0.18-r1)
(53/63) Installing alpine-sdk (0.4-r3)
(54/63) Installing ncurses-terminfo-base (6.0-r7)
(55/63) Installing ncurses-terminfo (6.0-r7)
(56/63) Installing ncurses-libs (6.0-r7)
(57/63) Installing readline (6.3.008-r4)
(58/63) Installing bash (4.3.42-r3)
(59/63) Installing libgit2-libs (0.24.1-r0)
(60/63) Installing libgit2 (0.24.1-r0)
(61/63) Installing openssh-client (7.2_p2-r3)
(62/63) Installing openssh-sftp-server (7.2_p2-r3)
(63/63) Installing openssh (7.2_p2-r3)
Executing busybox-1.24.2-r11.trigger
Executing ca-certificates-20160104-r4.trigger
OK: 198 MiB in 75 packages
---> f73132c8c72e
Removing intermediate container 7876608fa4e7
Step 4 : RUN pkg-config --print-errors --exists libgit2
---> Running in f69f97142e81
Package libgit2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libgit2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libgit2', required by 'world', not found
The command '/bin/sh -c pkg-config --print-errors --exists libgit2' returned a non-zero code: 1

So what is it that is wrong? Why it can not see the installed libgit2 (0.24.1-r0). I really tried every possible way to get this one package built and installed in my docker container and I can not simply do it. I have no idea what is wrong. Please help me.

-------------- EDIT

The last command in my Dockerfile is actually taken from here

And certainly the issue depicted there and the one that I have is not the same

---------------- EDIT 2

Anyone interested in doing the effort all by your self can follow this -

FROM golang:1.7-alpine
RUN echo >> /etc/apk/repositories
RUN apk update && apk upgrade && apk add --no-cache bash git openssh alpine-sdk libcurl
RUN apk update && apk add cmake
RUN git clone git://
RUN git checkout v0.24.0 && rm -rf build && mkdir build && cd build \
&& cmake .. -DCMAKE_INSTALL_PREFIX=$TARGET -DBUILD_CLAR=OFF && cmake --build . --target install
ENV PKG_CONFIG_PATH /go/libgit2/build/venv/lib/pkgconfig:$PKG_CONFIG_PATH

For a simpler and cleaner approach follow the accepted answer. This one only has the advantage of having libgit2 version which is not available via apk yet.


You are trying to compile a package using libgit2, so you need the libgit2-dev development package with the headers, pc file, etc.

This docker file file builds git2go successfully:

FROM golang:1.7-alpine
RUN apk update && apk upgrade && apk add --no-cache bash git openssh alpine-sdk libgit2-dev
RUN go get -v