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.
New self-hosted runner and select
Linux then copy the
Token number under the configure section.
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.
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.