GitLab 中文社区版 Docker 镜像
基于 GitLab 官方社区版 Docker 镜像制作的中文 Docker 镜像, 汉化补丁来自网友larryli (8.8.5之前), 后续由网友 xhang 维护。
由于汉化工作需要大量的人力, 所以中文版的版本会比官方的版本稍低, 如果刻意最求最新版, 请使用官方的 GitLab Docker 镜像。
如果发现汉化的问题, 请向 xhang 反映。
获取镜像
docker pull beginor/gitlab-ce:11.3.0-ce.0
运行
通常会将 GitLab 的配置 (etc) 、 日志 (log) 、数据 (data) 放到容器之外, 便于日后升级, 因此请先准备这三个目录。
sudo mkdir -p /mnt/sda1/gitlab/etc
sudo mkdir -p /mnt/sda1/gitlab/log
sudo mkdir -p /mnt/sda1/gitlab/data
sudo mkdir -p /mnt/sda1/gitlab/etc/ssl(配置ssl证书)
sudo chmod 700 /mnt/sda1/gitlab/etc/ssl
或者:
sudo mkdir /mnt/sda1/gitlab/{etc/ssl,data,log} -pv
也可细分:
sudo mkdir /mnt/sda1/gitlab/{etc/ssl/{key,crt},data,log} -pv
准备好这四个目录之后, 就可以开始运行 Docker 镜像了。 我的建议是使用unless-stopped 作为重启策略, 因为这样可以手工停止容器, 方便维护。
完整的运行命令如下:
docker run --detach \
--hostname centos \
--publish 40443:40443 \
--publish 40080:80 \
--publish 40022:22 \
--name gitlab \
--restart unless-stopped \
--volume /mnt/sda1/gitlab/etc:/etc/gitlab \
--volume /mnt/sda1/gitlab/log:/var/log/gitlab \
--volume /mnt/sda1/gitlab/data:/var/opt/gitlab \
--volume /mnt/sda1/gitlab/etc/ssl:/etc/gitlab/ssl \
--volume /mnt/sda1/gitlab/backups:/var/opt/gitlab/backups \
beginor/gitlab-ce:11.3.0-ce.0
如果需要开启SELINUX,则需要这样运行:
docker run --detach \
--hostname centos \
--publish 40443:40443 \
--publish 40080:80 \
--publish 40022:22 \
--name gitlab \
--restart unless-stopped \
--volume /mnt/sda1/gitlab/etc:/etc/gitlab:Z \
--volume /mnt/sda1/gitlab/log:/var/log/gitlab:Z \
--volume /mnt/sda1/gitlab/data:/var/opt/gitlab:Z \
--volume /mnt/sda1/gitlab/etc/ssl:/etc/gitlab/ssl:Z \
--volume /mnt/sda1/gitlab/backups:/var/opt/gitlab/backups:Z \
beginor/gitlab-ce:11.3.0-ce.0
也可以是如下命令,简化单词
docker run -d \
-p 40443:40443 \
-p 40080:80 \
-p 40022:22 \
--name gitlab \
--restart unless-stopped \
--volume /mnt/sda1/gitlab/etc:/etc/gitlab \
--volume /mnt/sda1/gitlab/log:/var/log/gitlab \
--volume /mnt/sda1/gitlab/data:/var/opt/gitlab \
--volume /mnt/sda1/gitlab/backups:/var/opt/gitlab/backups \
beginor/gitlab-ce:11.3.0-ce.0
或者添加SELINUX:
docker run -d \
-p 40443:40443 \
-p 40080:80 \
-p 40022:22 \
--name gitlab \
--restart unless-stopped \
--volume /mnt/sda1/gitlab/etc:/etc/gitlab:Z \
--volume /mnt/sda1/gitlab/log:/var/log/gitlab:Z \
--volume /mnt/sda1/gitlab/data:/var/opt/gitlab:Z \
--volume /mnt/sda1/gitlab/backups:/var/opt/gitlab/backups:Z \
beginor/gitlab-ce:11.3.0-ce.0
升级
小版本升级(例如从 8.8.2 升级到 8.8.3), 参照官方的说明, 将原来的容器停止, 然后删除:
docker stop gitlab
docker rm gitlab
然后重新拉一个新版本的镜像下来,
docker pull beginor/gitlab-ce:11.3.0-ce.0
还使用原来的运行命令运行,
docker run --detach \
--hostname centos \
--publish 40443:40443 \
--publish 40080:80 \
--publish 40022:22 \
--name gitlab \
--restart unless-stopped \
--volume /mnt/sda1/gitlab/etc:/etc/gitlab \
--volume /mnt/sda1/gitlab/log:/var/log/gitlab \
--volume /mnt/sda1/gitlab/data:/var/opt/gitlab \
--volume /mnt/sda1/gitlab/backups:/var/opt/gitlab/backups \
beginor/gitlab-ce:11.3.0-ce.0
GitLab 在初次运行的时候会自动升级, 为了预防万一, 还是建议先备份一下 /mnt/sda1/gitlab/ 这个目录。
大版本升级(例如从 8.7.x 升级到 8.8.x)用上面的操作有可能会出现错误, 如果出现错误可以尝试登录到容器内部, 可以用 docker exec , 也可以用 ssh ,
依次执行下面的命令:
sudo docker exec -it continerID /bin/bash
或者,仅仅只编辑/etc/gitlab/gitlab.rb
sudo docker exec -it gitlab vi /etc/gitlab/gitlab.rb
更新配置
gitlab-ctl reconfigure
gitlab-ctl restart
More
想知道更多高级的玩法, 请参考这些:
The official GitLab Community Edition Docker image is available on Docker Hub.
The official GitLab Enterprise Edition Docker image is available on Docker Hub.
The complete usage guide can be found in Using GitLab Docker images.
The Dockerfile used for building public images is in Omnibus Repository.
Check the guide for creating Omnibus-based Docker Image.
gitlab容器配置https
1、颁发自签证书
生成证书到/mnt/sda1/gitlab/etc/ssl
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj \
"/C=FR/ST=Charente/L=Mornac/O=Office/CN=www.gitlab-test.com" -keyout \
/mnt/sda1/gitlab/etc/ssl/www.gitlab-test.com.key -out /mnt/sda1/gitlab/etc/ssl/www.gitlab-test.com.crt
2、先启动容器
docker run --detach \
--hostname centos \
--publish 40443:40443 \
--publish 40080:80 \
--publish 40022:22 \
--name gitlab \
--restart unless-stopped \
--volume /mnt/sda1/gitlab/etc:/etc/gitlab \
--volume /mnt/sda1/gitlab/log:/var/log/gitlab \
--volume /mnt/sda1/gitlab/data:/var/opt/gitlab \
beginor/gitlab-ce:11.3.0-ce.0
3、停止容器
sudo docker stop gitlab
4、修改配置文件
vim /mnt/sda1/gitlab/etc/gitlab.rb
## GitLab URL
external_url 'https://test.kingtroldata.com:40443'
################################################################################
## GitLab NGINX
##! Docs: https://docs.gitlab.com/omnibus/settings/nginx.html
################################################################################
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['redirect_http_to_https_port'] = 80
nginx['ssl_certificate'] = "/etc/gitlab/ssl/www.gitlab-test.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/www.gitlab-test.com.key"
nginx['proxy_set_headers'] = {
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on",
}
####ldap
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'LDAP'
host: 'ad01.mdde.com'
port: 389
uid: 'sAMAccountName'
method: 'plain'
bind_dn: 'CN=gitlabadmin,CN=Users,DC=mdde,DC=com'
password: 'Mdddt88'
active_directory: true
allow_username_or_email_login: true
base: 'OU=maksad,DC=mdde,DC=com'
EOS
gitlab_rails['gitlab_shell_ssh_port'] = 22
####SMTP
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "mail.mdde.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "syssin@mdde.com"
gitlab_rails['smtp_password'] = "Masss"
gitlab_rails['smtp_domain'] = "mail.mdde.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
sudo docker start gitlab
或者
sudo docker exec -it continerID /bin/bash
或者,仅仅只编辑/etc/gitlab/gitlab.rb
sudo docker exec -it gitlab vi /etc/gitlab/gitlab.rb
更新配置
gitlab-ctl reconfigure
gitlab-ctl restart
Notice:
1、其次由于是测试环境,属于内网布设,因此需要服务器/etc/hosts
文件和 自身pc主机C:\Windows\System32\drivers\etc\hosts
中添加相关域名解析信息
具体如下:
192.168.1.196 www.gitlab-test.com
2、最好用Chrome浏览器,导入之前的自签证书www.gitlab-test.com.crt
文件。存至个人目录即可
3、第一次访问https://www.gitlab-test.com:40443/
然后会提示修改密码。
官方参考文档
https://docs.gitlab.com/omnibus/docker/
https://docs.gitlab.com/omnibus/settings/nginx.html#enable-https
https://gitlab.com/gitlab-org/gitlab-ce/issues?scope=all&utf8=%E2%9C%93&state=all