English · 中文 (繁體)
This repository provides a lightweight Docker-based GitHub Actions self-hosted runner image and a sample docker-compose setup to quickly run a runner on private infrastructure or in the cloud. The image is built from ubuntu:22.04, installs common tooling, and includes the GitHub Actions Runner binary.
- Engineers who want to quickly run a self-hosted GitHub Actions runner on internal or cloud hosts.
- CI/CD maintainers who need Docker-in-Docker support (via the host Docker socket) or other tools inside the runner.
Dockerfile- Builds the runner image and installs required dependencies.docker-compose.yml- Example service definition (github-runner).entrypoint.sh- Entrypoint script that registers and starts the runner when the container starts..env- (not tracked) Recommended place for runtime environment variables such asRUNNER_TOKEN.check-env.sh- Small helper script to print environment variables for quick verification.
- Clone the repository and change into the directory:
git clone <repo-url>
cd github-actions-runner- Create a
.envfile at the repository root with at least the following values:
# example .env
RUNNER_TOKEN=ghp_... # Token from GitHub (see below)
RUNNER_NAME=runner-01 # Optional runner/container name
RUNNER_LABELS="docker,X64,runner-01,self-hosted,Linux"- Start the runner using docker-compose:
# Run in foreground (shows logs)
docker compose up --build
# Or run in background
docker compose up -d --build- Stop and remove containers:
docker compose down- The
docker-compose.ymlmounts the host Docker socket (/var/run/docker.sock) into the container. This gives the container high privileges on the host (equivalent to root). Only enable this in trusted environments or when additional containment is in place. Remove the socket mount if the runner does not need to run Docker. RUNNER_TOKENis sensitive. Do not commit.envto a public repository. Use repository/org secrets or a secure secret management workflow when possible.- Review and harden the image and installed packages for production or corporate environments.
- The
Dockerfileinstalls dependencies (curl, wget, git, jq, unzip, python, docker, openjdk, etc.) and downloads/extracts the GitHub Actions Runner. - On container start
entrypoint.shsources.env(withset -a), checks for existing registration (looks for.runner) and runs./config.shto register the runner when needed. It then runs./run.shto start the runner process.
RUNNER_TOKEN(required): A registration token obtained from GitHub (Repository or Organization Settings → Actions → Runners → Add a new self-hosted runner).RUNNER_NAME(optional): The runner name to register; default example isrunner-01.RUNNER_LABELS(optional): Comma-separated labels used in workflows viaruns-on.
Use test.sh to quickly verify that .env is loaded correctly:
chmod +x test.sh
./test.shTo upgrade the GitHub Actions Runner version:
- Update the download URL/version in the
Dockerfile. - Rebuild the image and redeploy:
docker compose build --no-cache(ordocker build) thendocker compose up --build.
- Issues and pull requests are welcome.
- Describe the change and testing steps in your PR.
- For breaking changes or new features, update the README and document migration steps.
Use a workflow that targets the self-hosted runner labels:
jobs:
build:
runs-on: [self-hosted, docker, X64]
steps:
- uses: actions/checkout@v4
- run: echo "Running on self-hosted runner"- Q: How do I get
RUNNER_TOKEN? A: Create a new self-hosted runner from your repository or organization settings (Settings → Actions → Runners) and copy the generated token. - Q: Can I run multiple runners on the same host?
A: Yes. Give each runner a unique
RUNNER_NAMEand separate_workdirectories or volume mounts to avoid conflicts.
This project is licensed under the MIT License. See the LICENSE file for details.
Open an issue in the repository for questions or contact the maintainers on the project GitHub page.