ubuntu16下使用docker安装gitlab

首先安装docker社区版:参考官方文档 https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/

下载相关镜像

docker pull sameersbn/gitlab:latest
docker pull sameersbn/mysql:latest 
docker pull sameersbn/redis:latest
#创建目录
mkdir /data
mkdir /data/gitlab
mkdir /data/gitlab/log
mkdir /data/gitlab/data
mkdir /data/gitlab/mysql

#运行redis
docker run \
  --name=gitlab_redis \
  -tid \
  sameersbn/redis:latest

#运行mysql
docker run \
  --name=gitlab_mysql \
  -tid \
  -e 'DB_NAME=gitlabhq_production' \
  -e 'DB_USER=gitlab' \
  -e 'DB_PASS=password' \
  -v /data/gitlab/mysql:/var/lib/mysql \
  sameersbn/mysql:latest

GITLAB_SECRETS_DB_KEY_BASE,GITLAB_SECRETS_SECRET_KEY_BASE,GITLAB_SECRETS_OTP_KEY_BASE的值可以通过下面命令来生成:

pwgen -Bsv1 64

运行gitlab

docker run \
  -itd \
  --name gitlab \
  --link gitlab_mysql:mysql \
  --link gitlab_redis:redisio \
  -e 'GITLAB_HOST=git.ret.cn' \
  -e 'GITLAB_PORT=80' \
  -e 'GITLAB_SSH_PORT=10022' \
  -e 'GITLAB_SECRETS_DB_KEY_BASE=mrgtJHgHVj49xvdJWvFNXnfzMRwdCgcM4qRWd49pzN3jJCM9cVmqpvFkVRH4NmVz' \
  -e 'GITLAB_SECRETS_SECRET_KEY_BASE=MF44sxwtWFrmHnzss9WHW79VNsqFVfTRKfNThnJqtKwRJ3dmwzqbgCjx7g7HtTRg' \
  -e 'GITLAB_SECRETS_OTP_KEY_BASE=FVtPhhL4vcVnq94PMTW3RWv7Ftwc7WkzFTKM3MFJ94FfrzXdbxXXLNnLf9XPzJbj' \
  -p 10022:22 -p 10080:80 \
  -v /var/run/docker.sock:/run/docker.sock \
  -v $(which docker):/bin/docker \
  -v /data/gitlab/data:/home/git/data \
  -v /data/gitlab/log:/var/log/gitlab \
  -v /data/gitlab/config:/etc/gitlab \
  sameersbn/gitlab:latest

访问 http://ip:10080/
初始化密码 使用 root登录

开机启动服务

echo 'docker start gitlab_redis' >> /etc/rc.local
echo 'docker start gitlab_mysql' >> /etc/rc.local
echo 'docker start gitlab' >> /etc/rc.local

参考 : http://www.jianshu.com/p/bb89c84139a1

升级问题

ERROR 3009 (HY000) at line 1: Column count of mysql.user is wrong. Expected 45, found 42. Created with MySQL 50554, now running 50721. Please use mysql_upgrade to fix this error.
原因是镜像升级后没执行数据库升级命令,要下载mysql的镜像包,用docker-compose配置好挂载启动后进bash执行msyql_upgrade,然后退出删除,执行升级后的sameersbn/mysql
参考:https://github.com/sameersbn/docker-gitlab/issues/1486 ,注意老外写的命令有错,exex -> exec 才对。

yaml文件配置

version: '2'

services:
  redis:
    restart: always
    image: sameersbn/redis:latest
    command:
    - --loglevel warning

  mysql:
    restart: always
    image: sameersbn/mysql:latest
    volumes:
    - /data/docker/gitlab/mysql:/var/lib/mysql:Z
    environment:
    - DB_USER=gitlab
    - DB_PASS=password
    - DB_NAME=gitlabhq_production
    - DB_EXTENSION=

  gitlab:
    restart: always
    image: sameersbn/gitlab:latest
    depends_on:
    - redis
    - mysql
    ports:
    - "10080:80"
    - "10022:22"
    volumes:
    - /data/docker/gitlab/data:/home/git/data:Z
    - /data/docker/gitlab/log:/var/log/gitlab:Z
    - /data/docker/gitlab/config:/etc/gitlab:Z
    environment:
    - DEBUG=false

    - DB_ADAPTER=mysql2
    - DB_HOST=mysql
    - DB_PORT=3306
    - DB_USER=gitlab
    - DB_PASS=password
    - DB_NAME=gitlabhq_production

    - REDIS_HOST=redis
    - REDIS_PORT=6379

    - TZ=Asia/Shanghai
    - GITLAB_TIMEZONE=Beijing

    - GITLAB_HTTPS=false
    - SSL_SELF_SIGNED=false

    - GITLAB_HOST=10.88.1.163
    - GITLAB_PORT=80
    - GITLAB_SSH_PORT=10022
    - GITLAB_RELATIVE_URL_ROOT=
    - GITLAB_SECRETS_DB_KEY_BASE=char64
    - GITLAB_SECRETS_SECRET_KEY_BASE=char64
    - GITLAB_SECRETS_OTP_KEY_BASE=char64

    - GITLAB_ROOT_PASSWORD=666666
    - GITLAB_ROOT_EMAIL=a@b.c

文档中的备份命令会出现一个GRPC错误,参考 issue https://github.com/sameersbn/docker-gitlab/issues/1576

docker-compose exec gitlab su -c 'bundle exec rake gitlab:backup:create' git
#or
docker-compose exec gitlab /sbin/entrypoint.sh app:rake gitlab:backup:create

发表评论

电子邮件地址不会被公开。 必填项已用*标注