GitLab - 以Docker方式啟動GitLab


1 - GitLab鏡像

官網信息GitLab-CE:https://docs.gitlab.com/ce/install/docker.html
鏡像

2 - 拉取鏡像

命令
docker pull gitlab/gitlab-ce

實例

[root@h200 ~]# docker pull gitlab/gitlab-ce
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce
976a760c94fc: Pull complete 
c58992f3c37b: Pull complete 
0ca0e5e7f12e: Pull complete 
f2a274cc00ca: Pull complete 
984575bb5360: Pull complete 
f37421c0d9f0: Pull complete 
f5e6f94abad8: Pull complete 
d4082c13edfd: Pull complete 
51fbd684ae90: Pull complete 
e01aeeec631a: Pull complete 
Digest: sha256:07284eade0994f2b63edcdf57e8bed28b3cc95b9cd4eccab3ffaa3b190cd8171
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest
[root@h200 ~]# 
[root@h200 ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
jenkinsci/blueocean   latest              fee7a600b49c        30 hours ago        563MB
gitlab/gitlab-ce      latest              5737e50aaa01        43 hours ago        1.82GB
postgres              10                  1ba73c5b23e7        2 weeks ago         250MB
sonarqube             7.9.1-community     ea9ce8f562b5        2 weeks ago         480MB
sonarqube             7.5-community       88a9b8f332d0        10 months ago       843MB
hello-world           latest              fce289e99eb9        11 months ago       1.84kB
[root@h200 ~]#

3 - 創建容器

docker run -d \
-p 4430:443 -p 800:80 -p 220:22 \
--name gitlab \
--restart unless-stopped \
-v /opt/gitlab/config:/etc/gitlab \
-v /opt/gitlab/logs:/var/log/gitlab \
-v /opt/gitlab/data:/var/opt/gitlab \
-v /etc/localtime:/etc/localtime \
gitlab/gitlab-ce

參數解釋

  • -d:后台運行
  • -p:容器內部端口向外映射
  • --name:命名容器名稱
  • --restart:重啟策略
  • -v:將容器GitLab 的配置、 日志 、數據等文件夾掛載到宿主機指定目錄,便於日后升級
  • -v /etc/localtime:/etc/localtime :將容器時間和host設為同一個時區

實例

[root@h200 ~]# docker run -d -p 4430:443 -p 800:80 -p 220:22 --name gitlab --restart unless-stopped -v /opt/gitlab/config:/etc/gitlab -v /opt/gitlab/logs:/var/log/gitlab -v /opt/gitlab/data:/var/opt/gitlab -v /etc/localtime:/etc/localtime gitlab/gitlab-ce
118c5fc2cc0abef3207dacae52d043c3897228943649d5b8342fe3abf51b2ef2
[root@h200 ~]# 
[root@h200 ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                            PORTS                                                             NAMES
118c5fc2cc0a        gitlab/gitlab-ce      "/assets/wrapper"        11 seconds ago      Up 9 seconds (health: starting)   0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab                                                                        loving_nash
[root@h200 ~]# 
[root@h200 ~]# date
Thu Dec 19 17:45:17 CST 2019
[root@h200 ~]# 
[root@h200 ~]# docker exec -i gitlab date
Thu Dec 19 17:45:16 CST 2019
[root@h200 ~]#

4 - 開通防火牆端口

[root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=800/tcp
success
[root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=4430/tcp
success
[root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=220/tcp
success
[root@h200 ~]# 
[root@h200 ~]# firewall-cmd --reload
success
[root@h200 ~]#

5 - 配置GitLab主機名

以容器方式運行gitlab,在gitlab上創建項目時,生成項目的URL訪問地址是按容器ID來生成的,
需要配置gitlab.rb文件(GitLab的/etc/gitlab目錄)來指定一個更加明確的固定URL訪問地址。

添加如下內容並重啟GitLab容器

external_url 'http://192.168.16.200:800'
gitlab_rails['gitlab_ssh_host'] = '192.168.16.200'
gitlab_rails['gitlab_shell_ssh_port'] = 220

實例

[root@h200 ~]# vim /opt/gitlab/config/gitlab.rb 
[root@h200 ~]# 
[root@h200 ~]# cat /opt/gitlab/config/gitlab.rb |grep -v "#" |grep -Ev "^$"
external_url 'http://192.168.16.200'
gitlab_rails['gitlab_ssh_host'] = '192.168.16.200'
gitlab_rails['gitlab_shell_ssh_port'] = 220
[root@h200 ~]# 
[root@h200 ~]# docker restart gitlab
gitlab
[root@h200 ~]# 
[root@h200 ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                             PORTS                                                             NAMES
118c5fc2cc0a        gitlab/gitlab-ce      "/assets/wrapper"        26 minutes ago      Up 14 seconds (health: starting)   0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab                                                                             loving_nash
[root@h200 ~]# 
[root@h200 ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS                                                             NAMES
118c5fc2cc0a        gitlab/gitlab-ce    "/assets/wrapper"   44 minutes ago      Up 17 minutes (healthy)   0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab
[root@h200 ~]#

確認project信息是否已更改

6 -  數據留存

通過-v參數掛載的主機文件在容器停止或刪除后,仍然存在,可以在之后創建gitlab容器時,再次掛載。

[root@h200 ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                      PORTS                                                             NAMES
118c5fc2cc0a        gitlab/gitlab-ce      "/assets/wrapper"        47 minutes ago      Up 20 minutes (healthy)     0.0.0.0:220->22/tcp, 0.0.0.0:800->80/tcp, 0.0.0.0:4430->443/tcp   gitlab                                                                    loving_nash
[root@h200 ~]# docker stop gitlab
gitlab
[root@h200 ~]# docker rm gitlab
gitlab
[root@h200 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@h200 ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                      PORTS               NAMES
b69079fb1adb        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   42 hours ago        Exited (143) 41 hours ago                       myjenkins
9278594040d7        hello-world           "/hello"                 43 hours ago        Exited (0) 43 hours ago                         loving_nash
[root@h200 ~]# ll /opt/gitlab/
total 4
drwxrwxr-x  3 root root  239 Dec 19 17:11 config
drwxr-xr-x 20 root root 4096 Dec 19 17:11 data
drwxr-xr-x 20 root root  329 Dec 19 16:48 logs
[root@h200 ~]#

7 - 參考消息


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM