Mar 30, 2023 3 min read

How To Set Up A Github Actions Runner With Docker

I adopted Github Actions as my primary CICD platform for all the tooling and software projects but needed a way to host Github Actions runners inside a Docker container. Let's dive in on how to set up a Github Actions runner with Docker.

How To Set Up A Github Actions Runner With Docker
Github Actions With Docker
Table of Contents

Ever since I started adopting Github Actions as my primary CICD platform to build and deploy my projects it did not disappoint, today I am glad I made the switch and adopted Github Actions for my CICD workflows. However, I ran into a slight teensy problem which was hosting a Github Actions runner on one of my Docker hosts in my local network to deploy my apps locally and could not find a Docker configuration tutorial or documentation on the Github instruction pages. I decided to search if someone built a Dockerfile or Docker image or if I would go ahead and build one myself. What do you know I came across a couple but most importantly I came across one that works for me and I am sure it could work for you as well. Let's dive in on how to set up a Github Actions runner with Docker:

Login To Github And Register A Github Actions Runner

Before we go ahead with the Docker configuration we need to register a runner by going to the settings of the repo that you want to build a self-hosted runner for or the organization settings if you're building a runner for an organization that you're part of. For this exercise, I am building a runner for one of my public repositories on my personal Github account.

Once Navigated to the repository go to settings and then actions and select runners under actions in the drop-down menu.

Github Create Self-Hosted Runner

Click on New self-hosted runner and select Linux then copy the Token number under the configure section.

GitHub Actions Token Number

GitHub Actions Runner Docker Config And Setup

Once we retrieved our Github Actions Token we're ready to configure our Docker Compose file and deploy our Github Actions Runner in a Docker container. Let's jump right in, copy the docker-compose script below to one of your Docker hosts where you will run your runner, edit according to your configuration and run docker-compose up -d from your cli to deploy your GitHub Actions Runner.

version: '2.3'

services:
  worker:
    container_name: container-name
    image: myoung34/github-runner:latest
    restart: always
    environment:
      REPO_URL: https://github.com/user/repo-example
      RUNNER_NAME: repo-example
      RUNNER_TOKEN:
      RUNNER_WORKDIR: /tmp/runner/work
      ORG_RUNNER: 'false'
      LABELS: linux,x64,gpu
    security_opt:
      # needed on SELinux systems to allow docker container to manage other docker containers
      - label:disable
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'
      - '/tmp/runner:/tmp/runner'

Once successfully deployed you can either navigate to your docker logs or you can go back to the repo settings and see the status of your runner like in the example below.

Conclusion

In conclusion, I am a big fan of Github Actions since I adopted it as my primary CICD platform for all the software and tooling that I build. It is robust and reliable and comes with a huge open-source community that builds custom workflows and plugins and many open-source enthusiasts that help with questions in the communities as well. If you enjoyed this article consider signing up for our newsletter and don't forget to share it with people that would find it useful. Leave a comment below with a tutorial you would like us to cover.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Opensource Geeks.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.