Install gitlab-runner In Docker on Windows OS
Inspiration
- Upon executing
choco install gitlab-runner
, the following exception is thrown
Installation
Install Docker
Create Directory
- Create a new directory
mkdir %systemdrive%\Docker\gitlab-runner-home
Build docker image and run
- Execute the command below from the newly created directory.
- Be mindful that the
^
operator denotes a continuation onto a new line- the command below should be executed as a single line with
^
removed, unless executed from a.bat
file.
- the command below should be executed as a single line with
docker run ^
-v "%systemdrive%/Docker/gitlab-runner-home":/var/gitlab-runner-home ^
-v /var/run/docker.sock:/var/run/docker.sock ^
--name gitlab-runner ^
gitlab/gitlab-runner:latest
- Each flag from the above command is described more thoroughly below
%systemdrive%/Docker/gitlab-runner-home
- my created directory-v /var/run/docker.sock:/var/run/docker.sock
- mount/bid docker sockets--name gitlab-runner
- alias for created container - e.g. to be able login docker machine easilygitlab/gitlab-runner:latest
- name of docker used to containgitlab-runner
- Single line view below
docker run -v "%systemdrive%/Docker/gitlab-runner-home":/var/gitlab-runner-home -v /var/run/docker.sock:/var/run/docker.sock --name gitlab-runner gitlab/gitlab-runner:latest
Register a runner
docker run gitlab/gitlab-runner register
How Docker Commands Translate
To GitLab Runner Commands
- According to
https://docs.gitlab.com/runner/install/docker.html
:- The general rule is that every GitLab Runner command that normally would be executed as:
gitlab-runner [Runner command and options...]
- can be executed with:
docker run [docker options...] gitlab/gitlab-runner [Runner command and options...]
- The general rule is that every GitLab Runner command that normally would be executed as:
Interacting with Container
Running created container
- Execute the command below to run the newly created container.
docker container start gitlab-runner
Listing running container
docker container ls --all
- Executing the command above should yield an output comparable to that below.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
42e3edd6087b gitlab/gitlab-runner:latest "/sbin/tini -- /usr/…" 12 minutes ago Up 12 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp gitlab-runner
Stop container
- Execute the command below to stop the container.
- Note: You can also use Container ID instead alias name
docker container stop gitlab-runner
Remove container
- Execute the command below to remove the container.
- Note: Stopping and removing container is also required to be able rebuild docker (container)
docker container rm gitlab-runner
Remove image
- Execute the command below to remove the image.
docker image rm gitlab/gitlab-runner:latest
Bulk removing images and containers:
Windows:
@echo off
FOR /f "tokens=*" %%i IN ('docker ps -aq') DO docker rm %%i
FOR /f "tokens=*" %%i IN ('docker images --format ""') DO docker rmi %%i
Linux
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)