title: libgit2 alpine linux docker error
body: <p>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.</p>
  
  <p>This is my Dockerfile - </p>
  
  <pre><code>FROM golang:1.7-alpine
  RUN echo http://dl-4.alpinelinux.org/alpine/edge/testing &gt;&gt; /etc/apk/repositories
  RUN apk update &amp;&amp; apk upgrade &amp;&amp; apk add --no-cache bash git openssh alpine-sdk libgit2
  
  RUN pkg-config --print-errors --exists libgit2
  </code></pre>
  
  <p>I have wrote it with advice from here -  <a href="https://stackoverflow.com/questions/36803993/how-do-i-install-libgit2-on-alipne-linux">How do I install libgit2 on Alipne linux</a></p>
  
  <p>And this is the end result - </p>
  
  <pre><code>Sending build context to Docker daemon   513 kB
  Step 1 : FROM golang:1.7-alpine
   ---&gt; 161e259af05d
  Step 2 : RUN echo http://dl-4.alpinelinux.org/alpine/edge/testing &gt;&gt; /etc/apk/repositories
   ---&gt; Running in 428c62a1fc94
   ---&gt; 80a4e0dca9d7
  Removing intermediate container 428c62a1fc94
  Step 3 : RUN apk update &amp;&amp; apk upgrade &amp;&amp; apk add --no-cache bash git openssh alpine-sdk libgit2
   ---&gt; Running in 7876608fa4e7
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
  fetch http://dl-4.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
  v3.4.4-9-g07aa589 [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
  v3.4.4-1-g77d84e1 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
  v3.4.0-4072-g7fdcbdd [http://dl-4.alpinelinux.org/alpine/edge/testing]
  OK: 7381 distinct packages available
  (1/2) Upgrading libcrypto1.0 (1.0.2i-r0 -&gt; 1.0.2j-r0)
  (2/2) Upgrading libssl1.0 (1.0.2i-r0 -&gt; 1.0.2j-r0)
  Executing busybox-1.24.2-r11.trigger
  OK: 5 MiB in 12 packages
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
  fetch http://dl-4.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
  (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)
  Executing mkinitfs-3.0.5-r1.post-install
  (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)
  Executing bash-4.3.42-r3.post-install
  (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
   ---&gt; f73132c8c72e
  Removing intermediate container 7876608fa4e7
  Step 4 : RUN pkg-config --print-errors --exists libgit2
   ---&gt; 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
  </code></pre>
  
  <p>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.</p>
  
  <p>-------------- EDIT</p>
  
  <p>The last command in my Dockerfile is actually taken from here <a href="http://lists.subsurface-divelog.org/pipermail/subsurface/2014-November/015646.html" rel="nofollow noreferrer">http://lists.subsurface-divelog.org/pipermail/subsurface/2014-November/015646.html</a> </p>
  
  <p>And certainly the issue depicted there and the one that I have is not the same</p>
  
  <p>---------------- EDIT 2</p>
  
  <p>Anyone interested in doing the effort all by your self can follow this - </p>
  
  <pre><code>FROM golang:1.7-alpine
  ENV TARGET venv
  RUN echo http://dl-4.alpinelinux.org/alpine/edge/testing &gt;&gt; /etc/apk/repositories
  RUN apk update &amp;&amp; apk upgrade &amp;&amp; apk add --no-cache bash git openssh alpine-sdk libcurl
  RUN apk update &amp;&amp; apk add cmake
  RUN git clone git://github.com/libgit2/libgit2.git
  WORKDIR $GOPATH/libgit2
  RUN git checkout v0.24.0 &amp;&amp; rm -rf build &amp;&amp; mkdir build &amp;&amp; cd build \
      &amp;&amp; cmake .. -DCMAKE_INSTALL_PREFIX=$TARGET -DBUILD_CLAR=OFF &amp;&amp; cmake --build . --target install
  ENV PKG_CONFIG_PATH /go/libgit2/build/venv/lib/pkgconfig:$PKG_CONFIG_PATH
  </code></pre>
  
  <p>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. </p>
  
  <p>One more thing - <code>-DBUILD_CLAR=OFF</code> is there because I did not want to install Python in the image just to run the tests</p>