(1)查询可用docker镜像
docker search gitlab
如下:
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker search gitlab
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
gitlab/gitlab-ce GitLab Community Edition docker image based … 3439 [OK]
sameersbn/gitlab Dockerfile to build a GitLab image for the D… 1178 [OK]
gitlab/gitlab-runner GitLab CI Multi Runner used to fetch and run… 741 [OK]
gitlab/gitlab-ee GitLab Enterprise Edition docker image based… 283
twang2218/gitlab-ce-zh 汉化的 GitLab 社区版 Docker Image 249 [OK]
jangrewe/gitlab-ci-android GitLab CI image for building Android apps 59 [OK]
edbizarro/gitlab-ci-pipeline-php Docker images for build and test PHP applica… 38
ulm0/gitlab GitLab Docker image for ARM 36
gitlab/gitlab-runner-helper 34
klud/gitlab-runner GitLab Runner for ARM devices 27
centurylink/gitlab This image uses the image from sameersbn / g… 26 [OK]
ciricihq/gitlab-sonar-scanner Gitlab Docker container to run sonar-scanner… 16 [OK]
gitlab/gitlab-ce-qa GitLab QA has a test suite that allows end-t… 6
timoschwarzer/gitlab-monitor A browser-based monitor dashboard for GitLab… 4 [OK]
sgillespie/gitlab-runner A Dockerized GitLab Runner that automaticall… 3 [OK]
samcontesse/gitlab-merge-request-resource A concourse resource to check for new merge … 3 [OK]
mastertinner/gitlab-merge-request-resource A concourse resource to check for new merge … 2 [OK]
boldcommerce/gitlab-merge-request-resource Reverted build of Swisscom's resource until … 1 [OK]
stanfordlegion/gitlab-ci An image for Gitlab CI. 1 [OK]
lorands/gitlab-merge-request-resource This is a fork of swisscom/gitlab-merge-requ… 1 [OK]
edtan1/gitlab-merge-request-resource GitLab Merge Request resource for ConcourseCI 0 [OK]
adamkl/gitlab-merge-request-resource Customized with support for gitlab ssh on di… 0 [OK]
gitlab/gitlab-ee-qa GitLab QA has a test suite that allows end-t… 0
mvisonneau/gitlab-ci-pipelines-exporter Prometheus / OpenMetrics exporter for GitLab… 0 [OK]
onaci/gitlab-runner auto-registering gitlab runner 0
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]#
(2)下载镜像
docker pull gitlab/gitlab-ce
如下:
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker pull gitlab/gitlab-ce
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce
7b1a6ab2e44d: Pull complete
923d8a5a90cb: Pull complete
c9c193ad3afb: Pull complete
ca54c9617521: Pull complete
5c6b771a3e5e: Pull complete
b4823ec4057e: Pull complete
35db6611258b: Pull complete
cd101cdba14c: Pull complete
Digest: sha256:a67074548979a08eba93445c37a5dab09e2a8e4f29b301ec5fc7a05607293121
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest
[root@iZbp1flzt6x7pxmxfhmxeeZ ~]#
(3)启动服务
docker run -d -p 10008:80 -p 10009:443 -p 10010:22 --restart always --name gitlab -v /docker/gitlab/etc/gitlab:/etc/gitlab -v /docker/gitlab/var/log/gitlab:/var/log/gitlab -v /docker/gitlab/var/opt/gitlab:/var/opt/gitlab --privileged=true gitlab/gitlab-ce
(4)修改gitlab.rb文件
vi /docker/gitlab/etc/gitlab/gitlab.rb
修改如下位置:
# 如果使用公有云且配置了域名了,可以直接设置为域名,如下
external_url 'http://gitlab.redrose2100.com'
# 如果没有域名,则直接使用宿主机的ip,如下
external_url 'http://172.22.27.162'
# 同样如果有域名,这里也可以直接使用域名
gitlab_rails['gitlab_ssh_host'] = 'gitlab.redrosee2100.com'
# 同样如果没有域名,则直接使用宿主机的ip地址
gitlab_rails['gitlab_ssh_host'] = '172.22.27.162'
# 端口为启动docker时映射的ssh端口
gitlab_rails['gitlab_shell_ssh_port'] =10010
# 设置时区为东八区,即北京时间
gitlab_rails['time_zone'] = 'Asia/Shanghai'
(5)关于邮箱发邮件的配置如下
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com" # 邮箱服务器
gitlab_rails['smtp_port'] = 465 # 邮箱服务对应的端口号
gitlab_rails['smtp_user_name'] = "hitredrose@163.com" # 发件箱的邮箱地址
gitlab_rails['smtp_password'] = "xxxxxxxxxxx" # 发件箱对应的授权码,注意不是登录密码,是授权码
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'hitredrose@163.com' # 发件箱地址
gitlab_rails['gitlab_email_display_name'] = 'gitlab.redrose2100.com' # 显示名称
gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com' # 提示不要回复
(6) 重启docker
docker restart gitlab
(7)进入docker容器里
docker exec -it gitlab bash
(8)修改端口号
vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
如下,将端口修改为映射后的端口
(9)重启gitlab
直接在docker中执行
gitlab-ctl restart
如:
root@cd6a79be7773:/etc/gitlab# gitlab-ctl restart
ok: run: alertmanager: (pid 4567) 1s
ok: run: gitaly: (pid 4582) 1s
ok: run: gitlab-exporter: (pid 4598) 1s
ok: run: gitlab-workhorse: (pid 4603) 1s
ok: run: grafana: (pid 4610) 1s
ok: run: logrotate: (pid 4619) 1s
ok: run: nginx: (pid 4631) 1s
ok: run: postgres-exporter: (pid 4636) 1s
ok: run: postgresql: (pid 4645) 1s
ok: run: prometheus: (pid 4653) 0s
ok: run: puma: (pid 4670) 1s
ok: run: redis: (pid 4679) 0s
ok: run: redis-exporter: (pid 4689) 1s
ok: run: sidekiq: (pid 4697) 1s
ok: run: sshd: (pid 4703) 1s
root@cd6a79be7773:/etc/gitlab
(10)在浏览器打开 ip:端口号即可访问
这里需要注意,如果使用的是阿里云,需要配置安全组放开端口,如果使用二级域名,同样需要配置Nginx代理进行解析,
(11)查看root默认密码
cat /docker/gitlab/etc/gitlab/initial_root_password
如: