Gitlab----使用Docker方式安裝部署Gitlab

語言: CN / TW / HK

【原文連結】

(1)查詢可用docker映象

bash docker search gitlab 如下:

bash [[email protected] ~]# 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 [[email protected] ~]#

(2)下載映象

bash docker pull gitlab/gitlab-ce 如下:

bash [[email protected] ~]# 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 [[email protected] ~]#

(3)啟動服務

```bash 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檔案

bash vi /docker/gitlab/etc/gitlab/gitlab.rb 修改如下位置:

```bash

如果使用公有云且配置了域名了,可以直接設定為域名,如下

external_url 'http://gitlab.redrose2100.com'

如果沒有域名,則直接使用宿主機的ip,如下

external_url 'http://172.22.27.162'
```

```bash

同樣如果有域名,這裡也可以直接使用域名

gitlab_rails['gitlab_ssh_host'] = 'gitlab.redrosee2100.com'

同樣如果沒有域名,則直接使用宿主機的ip地址

gitlab_rails['gitlab_ssh_host'] = '172.22.27.162' ```

```bash

埠為啟動docker時對映的ssh埠

gitlab_rails['gitlab_shell_ssh_port'] =10010 ```

```bash

設定時區為東八區,即北京時間

gitlab_rails['time_zone'] = 'Asia/Shanghai'
```

(5)關於郵箱發郵件的配置如下

bash gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.163.com" # 郵箱伺服器 gitlab_rails['smtp_port'] = 465 # 郵箱服務對應的埠號 gitlab_rails['smtp_user_name'] = "[email protected]" # 發件箱的郵箱地址 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'] = '[email protected]' # 發件箱地址 gitlab_rails['gitlab_email_display_name'] = 'gitlab.redrose2100.com' # 顯示名稱 gitlab_rails['gitlab_email_reply_to'] = '[email protected]' # 提示不要回復

(6) 重啟docker

bash docker restart gitlab

(7)進入docker容器裡

bash docker exec -it gitlab bash

(8)修改埠號

bash vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml 如下,將埠修改為對映後的埠 在這裡插入圖片描述

(9)重啟gitlab

直接在docker中執行 bash gitlab-ctl restart 如:

bash [email protected]:/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 [email protected]:/etc/gitlab

(10)在瀏覽器開啟 ip:埠號即可訪問

這裡需要注意,如果使用的是阿里雲,需要配置安全組放開埠,如果使用二級域名,同樣需要配置Nginx代理進行解析, 在這裡插入圖片描述

(11)檢視root預設密碼

bash cat /docker/gitlab/etc/gitlab/initial_root_password 如:

(12)使用root使用者名稱以及上述查詢到的密碼登入

在這裡插入圖片描述

(13)登入後依次點選【頭像】-【Edit profile】-【password】,然後修改密碼

在這裡插入圖片描述

(14)至此,gitlab已經安裝完成,並已修改密碼