Before your getting started, you can read the official documentation and don't read this article 😉
So, if you're still here, let's do it together!💪
Pull the GitLab Runner Docker Image: Open your terminal and run the following command to pull the GitLab Runner Docker image:
docker pull gitlab/gitlab-runner:latest
Create new volume, it's a good practice to use a Docker volume to persist the config.toml file and ensure it remains available between container restarts. You can create a volume using:
docker volume create gitlab-runner-config
Run the GitLab Runner Container:
Next, run the GitLab Runner container. You can use the following command to start it in detached mode:
docker run -d --name yuit-gitlab-runner --restart always -v gitlab-runner-config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
This command does the following:
- Runs the container in detached mode:
-d
. - Names the container
yuit-gitlab-runner
. - Restarts the runner automatically if it stops:
--restart always
. - Maps the configuration directory via:
-v gitlab-runner-config:/etc/gitlab-runner
: This command mounts a Docker volume named gitlab-runner-config into the filesystem of the container at the specified path (/etc/gitlab-runner). - Add docker socket:
-v /var/run/docker.sock:/var/run/docker.sock
: This command mounts the host's Docker socket file (/var/run/docker.sock) at the same location inside the container.
Explanation of Docker Socket: By mounting the Docker socket, the GitLab Runner can use Docker to run builds as containers. This is necessary for scenarios where your CI/CD pipelines leverage Docker as an executor for running jobs, allowing the GitLab Runner to create and manage Docker containers during the job execution.
- Select CI/CD > Runners.
- Select New instance runner.
- In the Tags section, in the Tags field, enter the job tags to specify jobs the runner can run. If there are no job tags for this runner, select Run untagged:
yuit-runner-tag
- Runner description:
Runner of docker container
- Select the operating system where GitLab Runner is installed:
linux
Registering runners in local docker container
docker exec -it yuit-gitlab-runner gitlab-runner register
Enter the GitLab instance URL: https://gitlab.com
Enter the registration token: ****
Enter a name for the runner: yuit-runner
Enter an executor: docker
Enter the default Docker image: node:20.16-alpine
Top comments (0)