這上次我們講到如何自架 Gitlab 與 Gitlab-Runner 主機,今天我們來做一個細節調整,調整 gitlab-runner 可以直接跑 Docker 中的 shell,這樣我們就可以不用在下載 docker 的 image 去跑我們的 docker。
首先先查詢 docker 中的 gitlab runner container id,我們先下以下語法
docker container ls
然後會得到以下資訊
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bbafc34e717c gitlab/gitlab-runner:latest "/usr/bin/dumb-init …" 16 minutes ago Up 15 minutes gitlab_runner
5473ca18b304 gitlab/gitlab-ce:latest "/assets/wrapper" 16 minutes ago Up 8 minutes (healthy) 0.0.0.0:22->22/tcp, :::22->22/tcp, 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp gitlab-ce
接下來我們要進到 gitlab-runner container bash 裡面,輸入以下指令
docker exec -it bbafc34e717c bash
接下來我們直接在這個 gitlab-runner 安裝 docker,以下安裝指令,記得把 sudo 拿掉,先安裝 repository。
# Add Docker's official GPG key:
apt-get update
apt-get install ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
接下來安裝 docker package,這樣子我們一切都設定好了
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
我們再輸入一次以下指令
docker container ls
可以看到他跟本機是連通的
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bbafc34e717c gitlab/gitlab-runner:latest "/usr/bin/dumb-init …" 16 minutes ago Up 15 minutes gitlab_runner
5473ca18b304 gitlab/gitlab-ce:latest "/assets/wrapper" 16 minutes ago Up 8 minutes (healthy) 0.0.0.0:22->22/tcp, :::22->22/tcp, 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp gitlab-ce