This page describes how to install CircleCI’s machine runner with the Docker executor. If you are looking to set up self-hosted runners in a private Kubernetes cluster, please visit the Container runner page.
New recommended method (container runner)
The container runner is the recommended approach for running containerized jobs on self-hosted runners. Container runner offers the ability to seamlessly define, publish, and use custom Docker images during job execution, as well as the ability to easily manage dependencies or libraries through custom Docker images instead of enumerating dependencies as part of
steps in the
Machine-based approach with Docker
If you cannot use the container runner linked above, you can use Docker and install machine runners with the instructions below.
Additional prerequisites with Docker
The host needs to have Docker installed. Once the
runner container is started, the container will immediately attempt to start running jobs. The container will be reused to run more jobs indefinitely until it is stopped.
The number of containers running in parallel on the host is constrained by the host’s available resources and your jobs' performance requirements.
1. Create namespace and resource class
2. Create a Dockerfile that extends the machine runner image
Dockerfile.runner.extended file. In this example, Python 3 is installed on top of the base image.
RUN sudo apt-get update; \
sudo apt-get install --no-install-recommends -y \
3. Build the Docker image
docker build --file ./Dockerfile.runner.extended .
4. Start the Docker container
CIRCLECI_RESOURCE_CLASS=<resource-class> CIRCLECI_API_TOKEN=<runner-token> docker run --env CIRCLECI_API_TOKEN --env CIRCLECI_RESOURCE_CLASS --name <container-name> <image-id-from-previous-step>
When the container starts, it will immediately attempt to start running jobs.
Start the Docker container on server
When starting the docker container on server, the
LAUNCH_AGENT_API_URL environment variables will need to be passed in using the
CIRCLECI_RESOURCE_CLASS=<resource-class> CIRCLECI_API_TOKEN=<runner-token> agent_version=<agent_version_for_server> LAUNCH_AGENT_API_URL=<server_host_name> docker run --env agent_version --env LAUNCH_AGENT_API_URL --env CIRCLECI_API_TOKEN --env CIRCLECI_RESOURCE_CLASS --name <container-name> <image-id-from-previous-step>
Stopping the Docker container
docker stop <container-name>
Remove the Docker container
In some cases you might need to fully remove a stopped machine runner container from the system, such as when recreating a container using the same name.
docker stop <container-name>; docker rm <container-name>;