Unix

Docker로 Gitlab 설치하기

ForceCore 2019. 4. 22. 23:48

설치형으로 된 github 대체재가 필요한 때가 있다. 하지만 이것저것 설정하려면 귀찮으니 docker로 돌리는 것이 속편하다.

 

#!/bin/bash

https://docs.gitlab.com/omnibus/docker/
prefix=/home/data/docker

docker run \
    --hostname carnegie.boolbada.net \
    --publish 4443:4443 --publish 2222:22 \
    -e GITLAB_OMNIBUS_CONFIG="external_url 'https://carnegie.boolbada.net:4443/' gitlab_rails['gitlab_shell_ssh_port'] = 2222" \
    --name gitlab \
    --volume $prefix/gitlab/config:/etc/gitlab \
    --volume $prefix/gitlab/logs:/var/log/gitlab \
    --volume $prefix/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest
    # --restart always \

 

위와 같이 실행하면 한 번 에러가 날 것이다.

 

Running handlers:
There was an error running gitlab-ctl reconfigure:

letsencrypt_certificate[xxx.yyy.net] (letsencrypt::http_authorization line 3) had an error: RuntimeError: acme_certificate[staging] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/letsencrypt/resources/certificate.rb line 20) had an error: RuntimeError: [xxx.yyy.net] Validation failed for domain xxx.yyy.net

Running handlers complete

 

하지만 무시하고

docker start -a gitlab

으로 다시 실행해보면 잘만 될 것이다.

 

밑에는 삽질 기록.

 

------------------------------------------

 

매뉴얼에는 docker_host_port:443 이렇게 하라고 되어 있는데 틀렸다. 매뉴얼의 nginx 부분을 보면, external_url에 지정된 포트에 서버가 돈다고 되어있다 -_-;;; 모순되는 설명인데 nginx의 설명이 맞다. 만약에 위와 같이 해서 실패하면 gitlab.rb를 손으로 수정하는 수밖에...

 

접속이 안 되면 증상이...

$ curl -v https://localhost:4443
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 4443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:4443
* Closing connection 0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:4443

이런 식으로 나올 것이다.

 

필자는 도커 생성시 4443:443 처럼 docker 매뉴얼에 나온대로 해서 이것 저것 삽질하다가 

nginx['listen_port'] = 443

이렇게 gitlab.rb 를 수정함으로서 해결을 보았다.

 

이 글에 나온 것이 결정적인 힌트였다:

https://forum.gitlab.com/t/gitlab-docker-not-working-if-external-url-is-set/4110/6

 

Gitlab docker not working if external_url is set

Actually, it is very surprising behaviour! This way, after change external_url setting, I should also change not only external port mapping side in docker command, but also the internal side. So, 6080:80 become 6080:6080 if I set external_url 'http://192.1

forum.gitlab.com

 

설정이 마음에 들게 되었으면

docker update --restart=always gitlab

를 해줘서 재부팅 이후에 컨테이너도 재시작이 알아서 되게 하자.