docker-compose部署gitlab的詳細過程
一、gitlab介紹
GitLab是一個開源的、基于Git的版本控制系統(tǒng)。
1. 核心功能
- 代碼托管
- gitlab允許用戶創(chuàng)建項目,并將代碼存儲在這些項目中,方便用戶上傳和下載代碼,并支持多種編程語言,無論是個人開發(fā)者的小型項目,還是團隊協(xié)作的大型軟件項目,都可以使用gitlab來托管代碼。
- 版本控制
- gitlab可以記錄代碼的每一次更改,用戶可以查看提交歷史來了解代碼的演變過程。
- 持續(xù)集成/持續(xù)部署(CI/CD)
- gitlab通過CI/CD管道實現(xiàn)自動化構建、測試和部署。當開發(fā)正推送代碼后,gitlab會自動觸發(fā)構建和測試流程,測試通過后可以進行部署,可以提高開發(fā)效率。
- 項目管理
- gitlab項目管理工具,支持創(chuàng)建任務、分配任務、跟蹤任務進度,并可以設置里程碑,幫助團隊有效管理項目進度和任務分配。
- 代碼審查
- 開發(fā)可以通過合并請求提交代碼更改,團隊其他成員可以對代碼進行審查、評論和批準,有助于提高代碼質量。
- 安全功能
- gitlab提供代碼掃描功能,可以檢測代碼中的安全漏洞,并支持訪問控制,設置不同用戶或用戶組對項目的訪問權限。
2. 適用場景
- 軟件開發(fā)團隊
- 企業(yè)內部項目管理
- 開源社區(qū)項目
- 個人開發(fā)者
- 教育機構
- 小型團隊和初創(chuàng)公司
二、gitlab部署
以下是gitlab-18.2.4-ce部署
1. 環(huán)境準備
- 安裝docker和docker-compose
- 服務器配置最好 2核 4G 以上
2. 部署gitlab
2.1 創(chuàng)建目錄
mkdir -p /data/gitlab/config mkdir -p /data/gitlab/logs mkdir -p /data/gitlab/data
2.2 編寫docker-compose.yml文件
version: '3.8'
services:
gitlab:
image: gitlab/gitlab-ce:18.2.4-ce.0
container_name: gitlab
restart: always
hostname: gitlab.example.com
ports:
- "8080:80" # 給 Nginx 代理
- "8443:443" # 如果想用 GitLab 自帶 https,可選
- "2222:22" # ssh 克隆用
volumes:
- /data/gitlab/config:/etc/gitlab
- /data/gitlab/logs:/var/log/gitlab
- /data/gitlab/data:/var/opt/gitlab2.3 啟動gitlab容器
docker-compose up -d
3. 調整gitLab 內部配置
vim /data/gitlab/config/gitlab.rb (容器內部是/etc/gitlab/gitlab.rb)
#指定域名 #注意:為什么這里不寫https//gitlab.example.com,如果寫了https,gitLab內置nginx和外層nginx沖突,gitLab內部nginx會嘗試啟用443,而外層Nginx也在管443,結果請求來回繞,容易訪問502。 external_url 'http://gitlab.example.com' # 如果 ssh 用 2222 端口,需要加上: gitlab_rails['gitlab_shell_ssh_port'] = 2222 #因為用了Nginx 反向代理,那就 關閉 GitLab 的內置證書申請 letsencrypt['enable'] = false
更改完之后重載配置
docker exec -it gitlab gitlab-ctl reconfigure
4. gitlab其他操作
#殺掉進程(如果出現(xiàn)執(zhí)行重載配置是卡住可選擇操作)
docker exec -it gitlab pkill -9 -f "cinc-client"
docker exec -it gitlab gitlab-ctl reconfigure
#查看組件是否正常(各個組件顯示run就說明ok)
docker exec -it gitlab gitlab-ctl status
#GitLab 在 容器第一次初始化時,會生成一個隨機的 root 密碼,默認的登錄方式是:
用戶名:root
密碼:保存在容器掛載的配置目錄里(/etc/gitlab/initial_root_password)
#查看宿主機掛載位置
cat /data/gitlab/config/initial_root_password
#會有類似輸出(!?。∪绻倪^root密碼就不會更新這個文件了)
# WARNING: This value is valid only in the following conditions
# ...
Password: AbCdEfGhIjKlMnOpQrSt
# ...
#如果密碼忘記,可以進入容器里重置
docker exec -it gitlab gitlab-rails console -e production
#在控制臺輸入
user = User.find_by_username('root')
user.password = '你的新密碼'
user.password_confirmation = '你的新密碼'
user.save!三、配置nginx反向代理
1. 安裝nginx
#拉取nginx鏡像 docker pull nginx:1.26.2 #創(chuàng)建持久化目錄 mkdir -p /data/nginx/cert mkdir -p /data/nginx/conf/conf.d mkdir -p /data/nginx/html mkdir -p /data/nginx/logs
2. 創(chuàng)建nginx配置文件
創(chuàng)建基礎配置文件nginx.confvim /data/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
client_max_body_size 200m;
client_body_timeout 300;
include /etc/nginx/conf.d/*.conf;
}創(chuàng)建gitlab代理nginx配置文件
server {
listen 80;
server_name gitlab.example.com; # 替換為你的域名
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name gitlab.example.com; # 替換為你的域名
ssl_session_timeout 30m;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_certificate /etc/nginx/cert/certificate.pem; # 替換為你的 SSL 證書路徑
ssl_certificate_key /etc/nginx/cert/private.key; # 替換為你的 SSL 私鑰路徑
ssl_session_cache shared:SSL:10m;
location / {
client_max_body_size 256m;
proxy_pass http://localhost:8080; # 替換為 GitLab 容器的 IP 或域名
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_intercept_errors on;
}
# GitLab WebSocket 支持(例如 CI/CD 終端)
location /-/ {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}3. 重啟nginx
systemctl restart nginx
4.訪問gitlab
https://gitlab.example.com #訪問你自己的域名
到此這篇關于docker-compose部署gitlab的文章就介紹到這了,更多相關docker-compose部署gitlab內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
在Linux系統(tǒng)中使用Dockerfile創(chuàng)建Docker的完整步驟
Dockerfile是Docker用來構建鏡像的文本文件,包含自定義的指令和格式,這篇文章主要介紹了在Linux系統(tǒng)中使用Dockerfile創(chuàng)建Docker的相關資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2025-11-11
idea?連接遠程?docker?并部署項目到?docker的過程
這篇文章主要介紹了idea連接遠程docker并部署項目到docker,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-10-10
docker容器查看所有沒使用的鏡像并刪除的實現(xiàn)
本文主要介紹了docker容器查看所有沒使用的鏡像并刪除的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-08-08
Docker安裝mysql教程以及解決mysqld: Can‘t read dir&nbs
本文詳細介紹了如何通過Docker來安裝和配置MySQL數(shù)據(jù)庫,包括拉取MySQL鏡像、啟動MySQL容器、配置MySQL、解決常見錯誤等步驟,提供了詳盡的命令和參數(shù)說明,幫助用戶順利完成MySQL的安裝和配置,文中還提到了如何處理MySQL容器啟動時遇到的“無法讀取目錄”2024-10-10

