Quick start
这是官方文档中的运行命令
1 2 3 4 5 6 7 8 9
| sudo docker run --detach \ --hostname gitlab.example.com \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ --restart always \ --volume /srv/gitlab/config:/etc/gitlab:Z \ --volume /srv/gitlab/logs:/var/log/gitlab:Z \ --volume /srv/gitlab/data:/var/opt/gitlab:Z \ gitlab/gitlab-ce:latest
|
这是我自己搭建时使用的命令
1 2 3 4 5 6 7 8 9
| sudo docker run --detach \ --hostname git.taeroen.xyz \ --publish 1443:443 --publish 1080:80 --publish 1022:22 \ --name gitlab-ce \ --restart unless-stopped \ --volume /data/gitlab/config:/etc/gitlab:Z \ --volume /data/gitlab/logs:/var/log/gitlab:Z \ --volume /data/gitlab/data:/var/opt/gitlab:Z \ gitlab/gitlab-ce:8.17.2-ce.0
|
两者区别的地方就是可以自定义配置的地方,hostname只是个实例,如果有域名的话可以配成自己的,也可以更改自己的hosts来指向;端口的话随意,内部端口正确即可以;restart策略我更习惯使用unless-stopped,如果我手动stop后不会在下一次开机后重启;挂载目录的话可以看自己的需求,我习惯都挂载/data目录下;最后的tag建议改成一个固定值,实际上就是latest指向的值,这样避免升级时由于版本问题带来可能的bug。
进阶
实际使用时需要在启动时传一些额外的参数,例如lfs,external_url,可以在启动时添加额外的参数。
例如:
1 2
| GITLAB_OMNIBUS_CONFIG="external_url 'https://git.taeroen.xyz:1443/'; gitlab_rails['lfs_enabled'] = true; nginx['redirect_http_to_https'] = true; nginx['ssl_certificate'] = '/etc/letsencrypt/live/git.taeroen.xyz/fullchain.pem'; nginx['ssl_certificate_key'] = '/etc/letsencrypt/live/git.taeroen.xyz/privkey.pem';
|
配置Let’s Encrypt
1 2 3
| git clone https://github.com/letsencrypt/letsencrypt cd letsencrypt ./letsencrypt-auto --agree-tos --email taeroen@gmail.com certonly --webroot -w /usr/share/nginx/html/ -d git.taeroen.xyz
|
最终配置
1 2 3 4 5 6 7 8 9 10 11 12
| sudo docker run --detach \ --hostname git.taeroen.xyz \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab-ce \ --restart unless-stopped \ --volume /data/gitlab/config:/etc/gitlab:Z \ --volume /data/gitlab/logs:/var/log/gitlab:Z \ --volume /data/gitlab/data:/var/opt/gitlab:Z \ --volume /data/git.taeroen.xyz/fullchain.pem:/etc/gitlab/ssl/git.taeroen.xyz.crt \ --volume /data/git.taeroen.xyz/privkey.pem:/etc/gitlab/ssl/git.taeroen.xyz.key \ --env GITLAB_OMNIBUS_CONFIG="external_url 'https://git.taeroen.xyz/';gitlab_rails['lfs_enabled'] = true;" \ gitlab/gitlab-ce:8.17.2-ce.0
|