Category Archives: alpine

Apache git server with Alpine Linux on Docker

I am trying to serve git repos over http using Alpine's Apache image in Docker.

I am able to get Apache to serve up documents and folders over http (there are some non git repos in this folder, this is just a proof of concept at the moment, so they can be ignored):

docker alpine apache git

However when I attempt to clone the git repo's, I can only successfully clone the DynamicDockerTesting.git repo. When attempting to clone the other repo's I get

fatal: repository 'http://192.168.1.32/<repo-name>.git' not found

I have inspected every difference I can think of between DynamicDockerTesting.git 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.

Here are the contents of my Dockerfile

FROM httpd:alpine 

RUN mkdir -p /usr/local/apache2/git
RUN apk update && apk upgrade && apk add git git-gitweb apache2-utils apache2
COPY apacheGitServer.xml  /usr/local/apache2/
RUN cat /usr/local/apache2/apacheGitServer.xml >> /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

Alpine Apache seems to run everything out of /usr/local/apache2 (instead of /etc/apache2), so here I am just adding to the default httpd.conf the logic to deploy the repos, and also enabling the cgi module since it is disabled by default (env and alias are enabled by default).

Here are the contents of apacheGitServer.xml

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /usr/local/apache2/git/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<VirtualHost *:80>
    DocumentRoot /usr/local/apache2/git
    ServerName 192.168.1.32

    <Directory "/usr/local/apache2/git">
        Allow from All
        Options +Indexes +ExecCGI
        AllowOverride All
        AddHandler cgi-script cgi
    </Directory>

    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
</VirtualHost>

apacheGitServer.xml 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 DynamicDockerTesting.git)

With the Dockerfile and apacheGitServer.xml in the same folder, I have been building the image with

docker build -t apachegit .

and then I have cd'ed to the directory with my git repo's, and issued the command

docker run -d --name apachegitserver -p 80:80 -v $(pwd):/usr/local/apache2/git apachegit

I have spent two days trying to get this to work, so any guidance at this point is welcome.