[雲端] Docker / GitLab === ###### tags: `雲端`, `gitlab`, `docker` <br>  [TOC] <br> ## 官網 - https://docs.gitlab.com/omnibus/docker/ <br> ## 使用 Docker 映像檔安裝 (使用預設的 SSH / HTTP 埠) ```bash $ export GITLAB_HOME=$HOME/gitlab $ sudo docker run --detach \ --hostname 10.78.26.241 \ --publish 50443:443 --publish 50080:80 --publish 50022:22 \ --name gitlab \ --restart always \ --volume $GITLAB_HOME/config:/etc/gitlab \ --volume $GITLAB_HOME/logs:/var/log/gitlab \ --volume $GITLAB_HOME/data:/var/opt/gitlab \ gitlab/gitlab-ee:latest ``` :::warning :warning: **注意:以下用「 docker 」表示「 GitLab 容器 」的說法** ::: - ### 其中,docker 對外的埠為 - SSH: 50022 - 透過 public key 授權存取 - HTTP: 50080 - web - http://10.78.26.241:50080 - HTTPS: 50443 - web - https://10.78.26.241:50080 (如果有支援的話; 可以自製內部 self-signed CA) - ### 另外,資料備份的問題 - GitLab 設定檔(config)和原始碼(source code)是存放在**容器外部** - 即使重新安裝 docker (GitLab 容器),資料依然存在 - ### 我們來 get code 看看... ```bash # port: 50080 # or you will fail to connect to 10.78.26.241 port 80: Connection refused $ git clone http://10.78.26.241:50080/tj_tsai/tj-jenkins-project1.git ``` - OK - ### 但是這樣「 Clone UI 資訊 」會有一個問題  :::danger :information_source: **有沒有注意到,問題在那?** - docker 對外的 HTTP port 是 50080 - 但是,提供 clone 來源的 HTTP URL,**卻沒有 50080** ::: :::danger :information_source: **換個角度** - web URL 所使用的 HTTP port 是 50080 - 但是,提供 clone 來源的 HTTP URL,**卻沒有 50080** ::: :::warning :information_source: **比較差異性** - docker 對外的 port: 50080 - clone HTTP URL: http://10.78.26.241 <--- 有問題的地方 - web HTTP URL: http://10.78.26.241:50080 ::: - 拿 clone 來源的 HTTP URL 去 get code 會失敗 ```bash $ git clone http://10.78.26.241/tj_tsai/tj-jenkins-project1.git Cloning into 'tj-jenkins-project1'... fatal: unable to access 'http://10.78.26.241/tj_tsai/tj-jenkins-project1.git/': Failed to connect to 10.78.26.241 port 80: Connection refused ``` - docker 內部使用 80 - docker 外部使用 50080 - 在 get code 的時候,要使用 50080,所以 HTTP URL 要補上 ```:50080``` ```bash # 這樣才會成功 $ git clone http://10.78.26.241:50080/tj_tsai/tj-jenkins-project1.git ``` - **正確設置 SSH / HTTP 埠的解法,請看底下小節 ↓ ↓ ↓** <br> <hr> <br> ## 使用 Docker 映像檔安裝 (使用其他 SSH / HTTP 埠) - ### [步驟一] 先決定好 SSH / HTTP 埠 (自定義,使用一個沒人用過的埠) - SSH: 50020 - HTTP: 50080 - HTTPS: 50443 - ### [步驟二] docker 的內部埠,也要更著變 ```bash $ export GITLAB_HOME=$HOME/gitlab $ echo $GITLAB_HOME $ sudo docker run --detach \ --hostname "10.78.26.241" \ --publish 50443:50443 --publish 50080:50080 --publish 50022:50022 \ --name gitlab \ --restart always \ --volume $GITLAB_HOME/config:/etc/gitlab \ --volume $GITLAB_HOME/logs:/var/log/gitlab \ --volume $GITLAB_HOME/data:/var/opt/gitlab \ gitlab/gitlab-ee:latest ``` - ==注意:內外部的埠要一致== - ```--publish 50443:50443``` - ```--publish 50080:50080``` - ```--publish 50022:50022``` - 相同的提問 - [Docker gitlab container healthy but not accessible](https://forum.gitlab.com/t/docker-gitlab-container-healthy-but-not-accessible/20042) - [solution-part1](https://forum.gitlab.com/t/change-all-project-urls-to-use-ip-address/18544/9) - [solution-part2](https://forum.gitlab.com/t/change-all-project-urls-to-use-ip-address/18544/10) - ### [步驟三] 變更 GitLab 設定檔 - [Running gitlab-docker on custom ports](https://forum.gitlab.com/t/running-gitlab-docker-on-custom-ports/7811) ```bash # 先連線到 GitLab 容器 $ docker exec -it gitlab /bin/bash ``` --- ==**注意**:要變更 GitLab 設定檔 (config)== ```bash # 變更設定檔 $ nano /etc/gitlab/gitlab.rb # 按 [Ctrl+W] 搜尋,輸入關鍵字 # 按 [Alt+W] 尋找下一個 external_url "http://10.78.26.241:50080" # 這是變更 HTTP 埠 gitlab_rails['gitlab_shell_ssh_port'] = 50022 # 這是變更 SSH 埠 ``` --- ```bash # 重啟 GitLab 容器 $ docker restart gitlab # 查看 GitLab 容器是否已經準備好? $ docker ps -a Up 2 seconds (health: starting) <--- 還在啟動中,需要 1~2 分鐘以上 ``` --- 變更結果:  (讓顯示的 port 與 docker 外部 port 一致)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up