start.sh
echo "Starting Redis..." # 启动 redis container
docker run \
--name=gitlab_redis \
-tid \
sameersbn/redis:latest
echo "Starting MySQL..." # 启动 mysql container
mkdir -p /my/gitlab/mysql
docker run \
--name=gitlab_mysql \
-tid \
-e 'DB_NAME=gitlabhq_production' \
-e 'DB_USER=gitlab' \
-e 'DB_PASS=password' \
-v /mygitlab/mysql:/var/lib/mysql \ # 挂载服务器mysql目录
sameersbn/mysql:latest
echo "Starting gitlab..." # 启动 gitlab container
mkdir -p /my/gitlab/data
mkdir -p /my/gitlab/log
docker run \
--name='gitlab' \
-itd \
--link gitlab_mysql:mysql \ # link 启动的 mysql
--link gitlab_redis:redisio \ # link 启动的 redis
--env-file my_gitlab.conf \ # gitlab的配置文件
--publish=8000:80 \ # 服务器端口:docker内端口
--publish=2000:22 \ # 服务器端口:docker内端口
-v /var/run/docker.sock:/run/docker.sock \
-v $(which docker):/bin/docker \
-v /my/gitlab/data:/home/git/data \ # 挂载服务器文件data目录
-v /my/gitlab/log:/var/log/gitlab \ # 挂载服务器文件log目录
sameersbn/gitlab:7.10.4
以上脚本用来启动 gitlab, 下面依次解释带有注释的重要行。
首先启动 redis 和 mysql 的 container, 使用的是之前下载好的镜像。
在启动 mysql container 的时候新建了 /my/gitlab/mysql 目录,用来挂载docker内部的 /var/lib/mysql 目录。
启动 gitlab container, 使用 link 方式,link 到刚才创建的 redis 和 mysql。
publish 项用来做端口映射,8000:80 是服务器 gitlab host 端口和 gitlab docker 内端口的映射, 外部 web 80端口的请求可以通过 nginx 转发到 8000 端口,将映射到 docker 内部的 80 端口。2000:22,对应用来命令行操作。
挂载了两个新建目录 /my/gitlab/data /my/gitlab/log, 这样在 host 主机上就可以找到这些内容。
--env-file my_gitlab.conf 此处选项是通过 my_gitlab.conf 文件来作为配置文件启动, 下面介绍几个常用配置组。
my_gitlab.conf文件中的常用配置组。包括:
GITLAB HOST 配置 设置访问主页地址,以及 root 用户的初始密码
GITLAB_HOST=example.gitlab.com
GITLAB_TIMEZONE=UTC
GITLAB_ROOT_PASSWORD=password
EMAIL 配置 gitlab 平台的email设置
GITLAB_EMAIL: The email address for the GitLab server. Defaults to example@example.com.
GITLAB_EMAIL_DISPLAY_NAME: The name displayed in emails sent out by the GitLab mailer. Defaults to GitLab.
GITLAB_EMAIL_REPLY_TO: The reply to address of emails sent out by GitLab. Defaults to the noreply@example.com.
GITLAB_EMAIL_ENABLED: Enable or disable gitlab mailer. Defaults to the SMTP_ENABLED configuration.
SMTP 配置 gitlab需要email配置来做通知工作。
SMTP_ENABLED: Enable mail delivery via SMTP. Defaults to true if SMTP_USER is defined, else defaults to false.
SMTP_DOMAIN: SMTP domain. Defaults towww.gmail.com
SMTP_HOST: SMTP server host. Defaults to smtp.gmail.com.
SMTP_PORT: SMTP server port. Defaults to 587.
SMTP_USER: SMTP username.
SMTP_PASS: SMTP password.
SMTP_STARTTLS: Enable STARTTLS. Defaults to true.
SMTP_OPENSSL_VERIFY_MODE: SMTP openssl verification mode. Accepted values are none, peer, client_once and fail_if_no_peer_cert. Defaults to none.
SMTP_AUTHENTICATION: Specify the SMTP authentication method. Defaults to login if SMTP_USER is set.
Backups 配置 自动备份
GITLAB_BACKUP_DIR: The backup folder in the container. Defaults to /home/git/data/backups
GITLAB_BACKUPS: Setup cron job to automatic backups. Possible values disable, daily, weekly or monthly. Disabled by default
GITLAB_BACKUP_EXPIRY: Configure how long (in seconds) to keep backups before they are deleted. By default when automated backups are disabled backups are kept forever (0 seconds), else the backups expire in 7 days (604800 seconds).
GITLAB_BACKUP_TIME: Set a time for the automatic backups in HH:MM format. Defaults to 04:00.
nginx 配置
监听 80 端口转发服务器 8000 端口。