title: Apache git server with Alpine Linux on Docker
body: <p>I am trying to serve git repos over <code>http</code> using Alpine's Apache image in Docker.</p>
  
  <p>I am able to get Apache to serve up documents and folders over <code>http</code> (there are some non git repos in this folder, this is just a proof of concept at the moment, so they can be ignored):</p>
  
  <p><a href="https://i.stack.imgur.com/Ke9UQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ke9UQ.png" alt="docker alpine apache git"></a></p>
  
  <p>However when I attempt to clone the git repo's, I can only successfully clone the <code>DynamicDockerTesting.git</code> repo. When attempting to clone the other repo's I get </p>
  
  <pre><code>fatal: repository 'http://192.168.1.32/&lt;repo-name&gt;.git' not found
  </code></pre>
  
  <p>I have inspected every difference I can think of between <code>DynamicDockerTesting.git</code> and the other repo's present, but have not been able to find any meaningful difference that would explain why I can clone that particular repo, but none of the other ones. If you have suggestions as to how to figure out why this is the case I would love to hear them, but more importantly if you know what I am doing wrong in general, and how to deploy these repo's successfully using the docker-alpine-apache-git combination, I would be extremely grateful.</p>
  
  <p>Here are the contents of my <code>Dockerfile</code></p>
  
  <pre><code>FROM httpd:alpine 
  
  RUN mkdir -p /usr/local/apache2/git
  RUN apk update &amp;&amp; apk upgrade &amp;&amp; apk add git git-gitweb apache2-utils apache2
  COPY apacheGitServer.xml  /usr/local/apache2/
  RUN cat /usr/local/apache2/apacheGitServer.xml &gt;&gt; /usr/local/apache2/conf/httpd.conf
  RUN sed -i '/LoadModule alias_module modules\/mod_alias.so/aLoadModule cgi_module modules/mod_cgi.so' /usr/local/apache2/conf/httpd.conf
  </code></pre>
  
  <p>Alpine Apache seems to run everything out of <code>/usr/local/apache2</code> (instead of <code>/etc/apache2</code>), so here I am just adding to the default <code>httpd.conf</code> the logic to deploy the repos, and also enabling the <code>cgi</code> module since it is disabled by default (<code>env</code> and <code>alias</code> are enabled by default). </p>
  
  <p>Here are the contents of <code>apacheGitServer.xml</code></p>
  
  <pre><code>&lt;Directory /usr/share&gt;
      AllowOverride None
      Require all granted
  &lt;/Directory&gt;
  
  &lt;Directory /usr/local/apache2/git/&gt;
      Options Indexes FollowSymLinks
      AllowOverride None
      Require all granted
  &lt;/Directory&gt;
  
  &lt;VirtualHost *:80&gt;
      DocumentRoot /usr/local/apache2/git
      ServerName 192.168.1.32
  
      &lt;Directory "/usr/local/apache2/git"&gt;
          Allow from All
          Options +Indexes +ExecCGI
          AllowOverride All
          AddHandler cgi-script cgi
      &lt;/Directory&gt;
  
      SetEnv GIT_HTTP_EXPORT_ALL
      SetEnv GIT_PROJECT_ROOT /usr/local/apache2/git
      ScriptAlias /git/ /usr/libexec/git-core/git-http-backend
      #ScriptAlias / /usr/share/gitweb/gitweb.cgi
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><code>apacheGitServer.xml</code> has gone through a number of revisions as I have tried every configuration that I could think of to get this working, but to no avail. This configuration makes the repos accessible, but not clone-able (except, of course <code>DynamicDockerTesting.git</code>)</p>
  
  <p>With the <code>Dockerfile</code> and <code>apacheGitServer.xml</code> in the same folder, I have been building the image with</p>
  
  <p><code>docker build -t apachegit .</code></p>
  
  <p>and then I have <code>cd</code>'ed to the directory with my git repo's, and issued the command</p>
  
  <p><code>docker run -d --name apachegitserver -p 80:80 -v $(pwd):/usr/local/apache2/git apachegit</code></p>
  
  <p>I have spent two days trying to get this to work, so any guidance at this point is welcome.</p>
  
  <p>EDIT</p>
  
  <p><a href="https://i.stack.imgur.com/4GKlF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4GKlF.png" alt="top command inside container"></a></p>
  
  <p>running <code>top</code> I see that the process is owned by <code>daemon</code>, I have <code>cd</code>'ed to <code>/usr/local/apache2/git</code> from inside the container and run <code>chown -R daemon:daemon .</code>, but now when I clone:</p>
  
  <p><code>git clone http://192.168.1.32/git/ScalaOpenCV.git</code></p>
  
  <p>I get a <code>403</code>:</p>
  
  <p><code>fatal: unable to access 'http://192.168.1.32/git/&lt;repo name&gt;.git/': The requested URL returned error: 403</code></p>
  
  <p>(actually I get a <code>403</code> no matter if I change the permissions or not)</p>