Skip to content

Install Drone CI self-hosted with Docker runners

Run Drone CI behind your own VCS — server, autoscaler, runner topology, secrets, and the network shape that keeps build noise off your production cluster.

Drone CI is a small, opinionated build server built around a single idea: every step is a container, every pipeline is a YAML file in the repo, and the server only schedules — it never executes user code. That separation between server and runner is what makes the install scale and what dictates the network topology. This article covers the self-hosted install we deploy for clients who want to keep build traffic off the cloud-provider’s CI plan.

How to verify

docker ps --filter name=drone | head
curl -fsS https://drone.example.com/healthz
docker exec drone-server drone-server --version
docker logs --tail 100 drone-runner-docker
curl -fsS -H "Authorization: Bearer $DRONE_TOKEN" \
  https://drone.example.com/api/user/repos | jq '.[].slug'

The /healthz endpoint returns ok only when the database is reachable and the OAuth secrets resolve. If runners can’t see the server, the symptom is “build queued forever” — check that the runner’s DRONE_RPC_HOST points back at the server and that the shared DRONE_RPC_SECRET matches.

What’s happening

Drone has three roles. The server holds repo metadata, queues builds, and proxies the web UI; it talks to GitHub/GitLab/Gitea/Bitbucket via OAuth. The runner picks builds off the queue via gRPC, spawns the container steps on its local Docker (or Kubernetes, or shell, depending on the runner type), and streams logs back. The autoscaler (optional) spins runner VMs up and down on a cloud provider based on queue depth.

The two important properties: (1) the server never executes user-controlled code, so the blast radius of a malicious pipeline is the runner host, not the server; (2) the runner only needs outbound connectivity to the server’s gRPC port — you can put runners in any network, even behind NAT, and they’ll still pick up work. That’s what makes “build VM per tenant” practical.

The runner types you’ll actually use: drone-runner-docker (each step is a container on the runner host — the default), drone-runner-kube (each step is a pod in a Kubernetes namespace — when you already have a cluster), and drone-runner-exec (steps run as host shell commands — fast and dangerous, only for trusted internal pipelines).

The procedure

  1. OAuth app. Create an OAuth app in your VCS pointing the callback to https://drone.example.com/login. Save the client ID and secret.

  2. Server. Run as a container with a reverse proxy in front (Caddy, Traefik, or Nginx) doing TLS termination:

    docker run -d --name=drone-server --restart=always \
      -v /var/lib/drone:/data \
      -e DRONE_GITHUB_CLIENT_ID=$GH_CLIENT_ID \
      -e DRONE_GITHUB_CLIENT_SECRET=$GH_CLIENT_SECRET \
      -e DRONE_RPC_SECRET=$(openssl rand -hex 16) \
      -e DRONE_SERVER_HOST=drone.example.com \
      -e DRONE_SERVER_PROTO=https \
      -e DRONE_USER_CREATE=username:platform-admin,admin:true \
      -e DRONE_DATABASE_DRIVER=postgres \
      -e DRONE_DATABASE_DATASOURCE=postgres://drone:$PG_PW@db/drone?sslmode=require \
      -p 127.0.0.1:8080:80 \
      drone/drone:2

    The default SQLite backend is fine for a single-user evaluation; for any real install use Postgres so the server can be restarted or replaced without losing build history.

  3. Docker runner. One per host (or per tenant, if you want isolation):

    docker run -d --name=drone-runner-docker --restart=always \
      -v /var/run/docker.sock:/var/run/docker.sock \
      -e DRONE_RPC_PROTO=https \
      -e DRONE_RPC_HOST=drone.example.com \
      -e DRONE_RPC_SECRET=$DRONE_RPC_SECRET \
      -e DRONE_RUNNER_CAPACITY=4 \
      -e DRONE_RUNNER_NAME=runner-build-01 \
      -e DRONE_RUNNER_LABELS=zone:internal,arch:amd64 \
      drone/drone-runner-docker:1

    DRONE_RUNNER_CAPACITY is the number of concurrent pipelines per runner; size to vCPU divided by typical pipeline parallelism.

  4. Pipeline selection. A repo’s .drone.yml can route to a labeled runner:

    kind: pipeline
    type: docker
    name: build
    node:
      zone: internal      # matches DRONE_RUNNER_LABELS
    steps:
      - name: test
        image: golang:1.22
        commands: ["go test ./..."]
  5. Secrets. Repo-level via the UI for ad-hoc values; org-level for shared registry credentials; external secrets via the secrets extension API when secrets must come from Vault or a cloud KMS. Never echo $SECRET in a step — Drone redacts known secret values from logs, but a base64 of a secret is not redacted.

  6. Autoscaler (optional). Run as a separate container that talks to the server’s API and to a cloud provider; configure with DRONE_POOL_MIN, DRONE_POOL_MAX, and a provider plugin (AWS, GCP, DigitalOcean, Hetzner). Drone creates ephemeral runner VMs on demand and tears them down after an idle window. This is the right shape for spiky open-source-style workloads; for steady internal load, fixed runners are simpler.

  7. Promotion deployments. Drone has first-class “promote” semantics — a build can be promoted to an environment after passing tests, which is just an API call (drone build promote owner/repo BUILD env=prod). Pipelines guard on event: promote and target: prod.

Common pitfalls

  • exec runner on a shared host. Anyone with commit rights can rm -rf /. Only run exec on a single-purpose host with no other workloads.
  • Postgres password in DRONE_DATABASE_DATASOURCE plaintext. Use Docker secrets or a startup script that reads from a vault. The DSN ends up in docker inspect.
  • Runner with no resource cap. A pipeline that allocates 32 GB and forks 200 processes will OOM the host. Set DRONE_RUNNER_LIMIT_MEM and DRONE_RUNNER_LIMIT_CPU.
  • No image pinning. image: golang pulls latest every build; tomorrow’s build behaves differently than today’s. Pin to a specific tag or digest.
  • Stale OAuth scopes. Adding repos after the OAuth app was created sometimes needs a user-side re-authorize. The symptom is “404 on repository sync”.

We deploy Drone for clients who want CI close to their infrastructure — typically because their build artifacts go straight to internal registries and they don’t want every push leaving the network. The server, autoscaled runner pool, secret integration, and the promote-to-prod gates are the parts we operate; the .drone.yml files belong to the dev teams. That delivery model is described at /en/services/managed-operations/.