我正在尝试通过 http
为 git repos 提供服务在 Docker 中使用 Alpine 的 Apache 镜像。
我可以让 Apache 通过 http
提供文档和文件夹(此文件夹中有一些非 git repos,目前这只是一个概念证明,因此可以忽略):
但是,当我尝试克隆 git repo 时,我只能成功克隆 DynamicDockerTesting.git
repo 。当试图克隆其他 repo 时,我得到
fatal: repository 'http://192.168.1.32/<repo-name>.git' not found
我已经检查了我能想到的
DynamicDockerTesting.git
之间的所有差异。和其他 repo 的存在,但无法找到任何有意义的差异来解释为什么我可以克隆那个特定的 repo,但没有其他 repo。如果您有关于如何弄清楚为什么会这样的建议,我很想听听他们的意见,但更重要的是,如果您知道我通常做错了什么,以及如何使用 docker-alpine-apache 成功部署这些 repo -git 组合,我将不胜感激。这是我的
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 似乎用尽了
/usr/local/apache2
(而不是 /etc/apache2
),所以这里我只是添加到默认 httpd.conf
部署 repos 的逻辑,并启用 cgi
模块,因为它默认被禁用( env
和 alias
默认启用)。这里是
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
经历了多次修改,因为我尝试了所有我能想到的配置,但无济于事。此配置使存储库可访问,但不可克隆(当然 DynamicDockerTesting.git
除外)与
Dockerfile
和 apacheGitServer.xml
在同一个文件夹中,我一直在构建图像docker build -t apachegit .
然后我有
cd
'ed 到带有我的 git repo 的目录,并发出命令docker run -d --name apachegitserver -p 80:80 -v $(pwd):/usr/local/apache2/git apachegit
我花了两天时间试图让这个工作,所以在这一点上任何指导都是受欢迎的。
编辑
运行
top
我看到该进程归 daemon
所有, 我有 cd
'ed 到 /usr/local/apache2/git
从容器内部运行 chown -R daemon:daemon .
,但是现在当我克隆时:git clone http://192.168.1.32/git/ScalaOpenCV.git
我得到一个
403
:fatal: unable to access 'http://192.168.1.32/git/<repo name>.git/': The requested URL returned error: 403
(实际上我得到一个
403
无论我是否更改权限)
最佳答案
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend
这意味着任何 git 操作都应该涉及一个带有
/git/
的 URL。在其中(如 this setup 所示)。git clone http://192.168.1.32/git/<repo-name>.git
检查 apache 日志以查看
DynamicDockerTesting.git
之间是否有任何区别和其他人。检查所有权,如 shown here .
关于git - Docker 上带有 Alpine Linux 的 Apache git 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50321724/