在阿里云ECS上使用Docker快速搭建Gitlab
在阿里云ECS上使用Docker快速搭建Gitlab
安装Docker
安装命令: apt-get install docker.io
检查版本: docker -v
添加Docker加速器
可以自己配置加速器:https://dashboard.daocloud.io/mirror
或者使用阿里去的加速器,登录阿里云,进入容器Hub服务控制台,初始化加速器后,阿里云会为我们创建一个专属加速器地址,复制这个地址。
在/etc/docker/daemon.json中添加一段配置,如果没有该文件则创建。
{
    "registry-mirrors": ["<your accelerate address>"]
}
下载Gitlab
去在阿里云的镜像仓库搜索镜像,然后选一个镜像复制名称,如:registry.cn-hangzhou.aliyuncs.com/lab99/gitlab-ce-zh
前面配置好加速器后,Docker下载Gitlab镜像就很快了,执行命令:docker pull registry.cn-hangzhou.aliyuncs.com/lab99/gitlab-ce-zh,即下载刚刚选的镜像。
启动Gitlab
创建容器并启动,使用以下命令加载镜像registry.cn-hangzhou.aliyuncs.com/lab99/gitlab-ce-zh,并以gitlab为容器名,并指定容器暴露的端口为:44333,6060,2222,更多命令参数参考:Docker run 命令参数及使用
docker run --detach \
    --hostname gitlab.example.com \
    --publish 44333:443 --publish 6060:80 --publish 2222:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    registry.cn-hangzhou.aliyuncs.com/lab99/gitlab-ce-zh:latest
或者使用docker-compose来定义和运行Docker容器,参考:Docker Compose 概览
参考示例
web:
  image: 'registry.cn-hangzhou.aliyuncs.com/lab99/gitlab-ce-zh:latest'
  restart: always
  hostname: 'gitlab.wodedata.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://gitlab.wodedata.com:8929'
      gitlab_rails['gitlab_shell_ssh_port'] = 2289
      # Add any other gitlab.rb configuration here, each on its own line
  ports:
    - '8929:80'
    - '2289:22'
  volumes:
    - config:/etc/gitlab
    - data:/var/opt/gitlab
    - logs:/var/log/gitlab
登录
第一次启动 GitLab 后,使用下列默认用户和密码登录,并修改密码:
用户名: `root`
密码: `5iveL!fe`
配置gitlab
配置/srv/gitlab/config/gitlab.rb文件,修改以下几个重要选项:
external_url 'http://gitlab.wodedata.com'
gitlab_rails['gitlab_ssh_host'] = 'gitlab.wodedata.com'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
配置Apache做端口转发
执行命令:/etc/apache2/sites-available/gitlab.wodedata.com.conf,添加以下内容:
<VirtualHost *:80>
    ServerName gitlab.wodedata.com
    ProxyIOBufferSize 8192
    ProxyRequests Off
    ProxyVia Full
    ProxyPass / http://wodedata.com:6060/ smax=5 max=20 ttl=120 retry=300
    ProxyPassReverse / http://wodedata.com:6060/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
并复制一份到:/etc/apache2/sites-enabled/gitlab.wodedata.com.conf,然后apachectl configtest检查配置是否正确,再apachectl restart重启Apache。
Tips
使用下面的命令进入 docker 环境中名为 gitlabe 的 bash中:
docker exec -it gitlab bash
 
 