環境
ubuntu15.04
dockerがインストールされている状態
dockerコンテナのOSはcentos6.6を利用
github互換サーバに gitprep を利用
概要
- docker pullで centos6を取得する
- github互換サーバ用のDockerfileを作成する
- フロントにnginxでWebサーバを起動しEXPOSEでポートをつなぐ
手順
- docker pullで centos6を取得する
jdeathe/centos-sshがcentos6.6のイメージによさそうだったので選択
sudo docker pull jdeathe/centos-ssh
- github互換サーバ用のDockerfileを作成する
mkdir ~/gitServer; cd ~/gitServerv
vi Dockerfile
---
FROM jdeathe/centos-ssh
RUN yum update -y
RUN yum install -y \
bzip2 \
git \
gcc \
perl-Archive-Tar \
perl-Encode \
perl-Scalar-List-Utils \
perl-PathTools \
perl-Text-Markdown \
perl-DBI \
perl-Time-HiRes \
perl-Sub-Identify \
perl-Digest-SHA \
perl-ExtUtils-MakeMaker \
; curl -L http://xrl.us/cpanm > /usr/bin/cpanm \
; chmod +x /usr/bin/cpanm \
; cpanm Archive::Tar \
Validator::Custom \
Params::Check \
Module::Load::Conditional \
Perl::OSType \
IPC::Cmd \
; cpanm Text::Markdown::Hoedown
RUN cd /opt ; git clone https://github.com/yuki-kimoto/gitprep.git gitprep \
; cd /opt/gitprep ; sh ./setup.sh \
; git config --global user.name "gitprep" \
; git config --global user.email "root@localhost"
ADD ./gitprep /etc/init.d/gitprep
RUN chmod +x /etc/init.d/gitprep \
; ln -s /etc/init.d/gitprep /etc/rc3.d/S99gitprep \
; ln -s /etc/init.d/gitprep /etc/rc3.d/K99gitprep \
; chkconfig --add /etc/init.d/gitprep \
; sed -i -e 's/^;on=1/on=1/' -e 's/^;path_depth=1/path_depth=1/' /opt/gitprep/gitprep.conf
EXPOSE 22 10020
ENTRYPOINT /etc/init.d/gitprep start \
; /etc/init.d/docker-registry start \
; /bin/bash
---
※gitの初期設定は適宜環境に合わせてください。
vi gitprep
---
#!/bin/sh
# chkconfig: 2345 99 10
# description: gitprep
prog="/opt/gitprep/gitprep"
case "$1" in
start)
$prog \
&& echo $prog started. \
&& exit 0
;;
stop)
$prog -s \
&& exit 0
;;
configtest|test|status)
$prog -t && exit 0
;;
reload|restart)
$prog -s \
&& $prog \
&& echo $prog started. \
&& exit 0
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest|status}"
exit 2
esac
---
sudo docker build -t gitServer .
sudo docker run -d \
-it \
--name gitServer \
gitServer \
/bin/bash
ココで、 -p で 10020番ポートをホストOSとつなぐ必要は無し
–name に指定した名前が重要となる。後で出てくるfrontサーバは、このnameに対してProxyの接続を行う。
- フロントにnginxでWebサーバを起動しEXPOSEでポートをつなぐ
mkdir ~/front ; cd ~/front
vi Dockerfile
---
FROM jdeathe/centos-ssh
RUN yum update -y
RUN yum install -y \
bzip2 \
git \
nginx \
; git config --global user.name "gitprep" \
; git config --global user.email "root@localhost"
COPY ./default /etc/nginx/default.d/gitserver.conf
EXPOSE 80
ENTRYPOINT /etc/init.d/nginx start \
; /bin/bash
---
※gitの初期設定は適宜環境に合わせてください。
vi gitserver.conf
---
# gitprep
location / {
proxy_pass http://gitServer:10020;
}
---
sudo docker build -t front .
sudo docker run -d \
-it \
-p 80:80 \
--link gitServer:gitServer \
--name front \
front \
/bin/bash
これで、ホストOSの80番ポート → frontコンテナの80番ポート → gitServerの10020番ポート とつながります。
git pushの問題
git push した際に、以下のようなエラーが発生する場合はバッファ値の設定が小さい為です。
Username for 'http://URL': ID
Password for 'http://URL': PASS
Counting objects: 49, done.
Compressing objects: 100% (44/44), done.
error: RPC failed; result=56, HTTP code = 200
fatal: The remote end hung up unexpectedly
Writing objects: 100% (47/47), 71.19 MiB | 5.79 MiB/s, done.
Total 47 (delta 8), reused 0 (delta 0)
fatal: The remote end hung up unexpectedly
Everything up-to-date
起動スクリプトに以下の環境変数をセットします
/etc/init.d/gitprep
---
export MOJO_MAX_MESSAGE_SIZE=1024000000
--
gitコマンドのglobal設定のpostbufferを大きく(1GB)します。上記Dockerfileに以下を追加しておきます。
git config http.postBuffer 1024000000