環境說明
系統環境 macOS
docker
原文地址
部署需求
docker 安裝是必須的,可參考docker安裝指引
提示:若使用持久卷(the persisted volumes) ,建議安裝原生的docker,而不是Docker Toolbox。
運行鏡像
運行鏡像
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 \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
上述命令將下載並啓動 GitLab CE 容器,對外訪問端口 SSH、HTTP和HTTPS。所有
GitLab 數據將被存儲在/srv/gitlab/ 這個目錄下。該容器將在系統重啓時自動重啓。
現在,你可以通過web地址訪問。
提示:如下是我自己測試時的運行命令
docker pull gitlab/gitlab-ce docker run --detach \ --hostname gitlab.example.com \ --publish 8443:443 --publish 8080:80 \ --name gitlab \ --restart always \ --volume /Volumes/MacSoft/data/gitlab/config:/etc/gitlab \ --volume /Volumes/MacSoft/data/gitlab/logs:/var/log/gitlab \ --volume /Volumes/MacSoft/data/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce:latest docker exec -it gitlab bash
如果你運行的系統打開了SELinux,則需要用如下命令
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
這將確保Docker進程有足夠的權限在被掛載的捲上去創建配置文件。
數據存儲在哪?
本地位置 | 容器位置 | 描述 |
---|---|---|
/srv/gitlab/data | /var/opt/gitlab | 存儲應用數據 |
/srv/gitlab/logs | /var/log/gitlab | 存儲日誌 |
/srv/gitlab/config | /etc/gitlab | 存儲GitLib 配置文件 |
你也可以微調這些目錄,去滿足你的需求。
配置GitLib
-
這個容器使用的官方Omnibus GitLab 包,因此所有配置被設定在唯一的配置文件 /etc/gitlab/gitlab.rb
- 你可以在一個運行中的容器環境下啓動一個shell 回話,去訪問GitLib 配置文件。這將允許你去訪問所有的目錄並使用你喜歡的編輯器去編輯他。
sudo docker exec -it gitlab /bin/bash
- 你也可以直接編輯 /etc/gitlab/gitlab.rb
sudo docker exec -it gitlab vi /etc/gitlab/gitlab.rb
首先打開/etc/gitlab/gitlab.rb 確認設置參數 external_url指向了有效的URL
-
若從GitLib 接收郵件,你必須配置SMTP setting 項,因爲GitLib Docker 鏡像沒有安裝 SMTP 服務。
- 你也可能願意 Enabling HTTPS。
所有的配置修改後,你需要重啓容器,GitLab 配置才能生效。
sudo docker restart gitlab
提示:每次容器啓動,GitLab會重置配置。更多的配置選項可以參考Omnibus GitLab 文檔。
前置配置 Docker 容器
你可以前置配置GitLab Docker 鏡像,在Docker 運行命令時通過添加 --env 參數 GITLAB_OMNIBUS_CONFIG。這個參數可以包括任意gitlab.rb 的設置,並將在加載容器內gitlab.rb文件前被生效。
通過這個方法,你可以很容易的配置GitLab的 external_url ,設置任意的數據庫配置或其他Omnibus GitLab的配置選項。
提示:這個設置包括在GITLAB_OMNIBUS_CONFIG 參數下,配置內容不會寫入gitlab.rb 中,僅在容器每次啓動時被生效。
如下例子是當容器啓動時設置外部URL 並打開LFS 支持。
sudo docker run --detach \
--hostname gitlab.example.com \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://my.domain.com/'; gitlab_rails['lfs_enabled'] = true;" \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
提示: 每次執行“docker run” 命令,你都需要指定“GITLAB_OMNIBUS_CONFIG” 參數,這個參數的內容是不會在每次“docker run” 後存儲的。
配置GitLab時,環境變量的數量也是有限制的。具體可參看GitLab 文檔的環境變量章節。
啓動容器後
啓動容器後,你可以訪問http://localhost 或 http://192.168.59.103 如果你用 boot2docker. 可能也需要等一段時間才能響應你的請求操作。
提示: 初始命令可能花費很長時間。你可以用“sudo docker logs -f gitlab ” 這個命令跟蹤查看日誌。當你第一次訪問GitLab 時,你將被要求設置admin 密碼。你設置密碼後,就可以用用戶名 root 和剛纔設置的密碼登陸了。
更新GitLab
運行GitLab CE 在一個外網IP
你可以將Docker 容器用你自己的IP地址,將docker 的所有流量都轉發到 --publish 參數指定的IP 地址
sudo docker run --detach \
--hostname gitlab.example.com \
--publish 1.1.1.1:443:443 \
--publish 1.1.1.1:80:80 \
--publish 1.1.1.1:22:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
提示: 你可以通過http://1.1.1.1 或 https://1.1.1.1 訪問GitLab
轉發GitLab 到不同的端口
略
診斷潛在的問題
讀取Docker 容器日誌
sudo docker logs gitlab
進入運行中的容器
sudo docker exec -it gitlab /bin/bash
進入到容器內,你可以管理GitLab 容器
安裝GitLab 用 docker-compose
利用 Docker compose 你可以很容易的配置、安裝和升級GitLab 基礎Docker
1、安裝 Docker Compose
2、創建 docker-compose.yaml 文件(或下載一個樣例)
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.example.com'
#Add any other gitlab.rb configuration here, each on its own line
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- '/srv/gitlab/config:/etc/gitlab'
- '/srv/gitlab/logs:/var/log/gitlab'
- '/srv/gitlab/data:/var/opt/gitlab'
3、確認你與docker-compose.yaml
文件在同一目錄,執行docker-compose up -d
啓動GitLab
閱讀“前置配置 Dokcer 容器”章節可以瞭解GITLAB_OMNIBUS_CONFIG
參數是如何工作的。
如下是 docker-compose.yaml 定義GitLab 運行在一個自定義 HTTP 和 SSH 端口的例子。注意,GITLAB_OMNIBUS_CONFIG
的參數內容可參見 ports 部分
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.example.com:9090'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '9090:9090'
- '2224:22'
volumes:
- '/srv/gitlab/config:/etc/gitlab'
- '/srv/gitlab/logs:/var/log/gitlab'
- '/srv/gitlab/data:/var/opt/gitlab'
這裏同樣使用 --publish 9090:9090 --publish 2224:22
更新 GitLab 用Docker compose
如果你安裝 GitLab 用 docker-compose ,你可以運行 docker-compose pull
和 docker-compose up -d
去下載新的版本並更新你的GitLab 實例。
安裝 GitLab 到一個集羣
略
名詞解析
持久卷(the persisted volumes):
https://www.cnblogs.com/leidaxia/p/6485646.html