容器運作Gitlab-Runner時無法使用docker指令
- 系統版本:Ubuntu 7.4.0-1ubuntu1~18.04.1
- Gitlab:9.5.9
- docker:19.03.1
在容器中運作Gitlab-Runner:
參考官網位址:
https://docs.gitlab.com/runner/install/docker.html
這裡沒什麼好說的,官方資料非常詳細。
注冊Gitlab-Runner:
參考官網位址:
https://docs.gitlab.com/runner/register/index.html
問題就出在這一步。
在初始注冊完成後,我們還需要編輯config.toml,官網給出的本地挂載目錄為:
/srv/gitlab-runner/config
我們在建立Gitlab_Runner容器的時候,可以自行定義。
将config.toml中volumes改為:
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
這樣在容器中裝載/var/run/docker.sock,使建構的容器儲存在主控端本身的鏡像存儲中。
否則可能會報錯誤:
gitlab runner Cannot connect to the Docker daemon at unix ///var/run/docker.sock. Is the docker daemon running?
更多詳細資料參考官網:https://docs.gitlab.com/runner/