DEV Community

YuIT Solutions
YuIT Solutions

Posted on • Edited on

Let's create a GitLab Runner 🏃 in a docker container📦

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!💪

  1. 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

  2. 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

  3. 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.

Register runner in gitlab

  • Select CI/CD > Runners.
  • Select New instance runner. new runner in gitlab
  • 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 new runner detail form new runner in gitlab token

Registering runners in local docker container

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

registered a new runner

See the new runner

Top comments (0)

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

👋 Kindness is contagious

If you found this post helpful, please leave a ❤️ or a friendly comment below!

Okay