This guide provides detailed instructions for setting up a self-hosted GitHub Actions Runner using Docker. You can choose to run the container with docker run
or docker-compose
.
Before starting, ensure you have the following:
-
Docker Installed
Ensure Docker is installed and running on your system. You can follow the official installation guide for help. -
Docker Compose (Optional)
If usingdocker-compose
, ensure it is installed. You can find installation instructions in the official Docker Compose guide. -
GitHub Runner Token
- Go to your GitHub repository or organization.
- Navigate to Settings > Actions > Runners.
- Click Add Runner and copy the registration token provided.
You can set up the runner using either docker run
or docker-compose
. Choose the method that suits your setup.
-
Docker Run
docker run -d \ -e GITHUB_URL=https://github.com/<your-org-or-repo> \ -e RUNNER_TOKEN=<your-runner-token> \ -e RUNNER_NAME=<your-runner-name> \ --name <container-name> \ chaddyc/gha-runner:latest
-
Docker Compose
services: github-runner: image: chaddyc/gha-runner:latest container_name: <container-name> environment: - GITHUB_URL=https://github.com/<your-org-or-repo> - RUNNER_TOKEN=<your-runner-token> - RUNNER_NAME=<your-runner-name> restart: unless-stopped
-
Docker Compose - Multi Containers
services: github-runner: image: chaddyc/gha-runner:latest #container_name: <container-name> #don't use container name when deploying multi replica containers of your gha-runner deploy: mode: replicated replicas: 2 environment: - GITHUB_URL=https://github.com/<your-org-or-repo> - RUNNER_TOKEN=<your-runner-token> - RUNNER_NAME=<your-runner-name> restart: unless-stopped
-
Kubernetes Deployment
Create a new kubernetes secret for your Github Actions Runner Token like in the example below:
kubectl create secret generic gha-runner-secret \ --from-literal=RUNNER_TOKEN=<your-runner-token>
Create a kubernetes deployment
yaml
and call itgha-runner-deployment.yml
and copy the below yaml file and update where needed such as theimage tag
if using aspecific version
other thanlatest
:apiVersion: apps/v1 kind: Deployment metadata: name: gha-runner-deployment labels: app: gha-runner spec: replicas: 1 # Number of runner instances selector: matchLabels: app: gha-runner template: metadata: labels: app: gha-runner spec: containers: - name: gha-runner image: chaddyc/gha-runner:latest # Replace Docker image tag if not going to use latest imagePullPolicy: IfNotPresent env: - name: GITHUB_URL value: "https://github.com/<your-org-or-repo>" # Replace with your GitHub URL org or repo - name: RUNNER_NAME value: "<your-runner-name>" # Name you want to give your runner - name: RUNNER_TOKEN # pull runner token from secret value created valueFrom: secretKeyRef: name: gha-runner-secret # Kubernetes Secret name key: RUNNER_TOKEN # Key in the secret holding the token resources: limits: cpu: "4" memory: "8Gi" requests: cpu: "2" memory: "4Gi"
Run the below command to create your deployment - ensure that you are in the correct
namespace
where you want to deploy your runner:kubectl apply -f gha-runner-deployment.yml