composebuilder

Docker Compose: Woodpecker CI Server and Agent with Gitea

Run a Woodpecker CI server and agent in Docker Compose, connected to Gitea over OAuth. Covers the shared agent secret, the Docker socket risk and HTTPS setup.

When to use this stack

Woodpecker is a continuous integration system that runs pipelines defined in a .woodpecker YAML file inside each repository. The server receives webhooks from the forge, schedules work, and stores results. Agents execute the steps, usually in Docker containers. This stack connects Woodpecker to a Gitea instance, so every push or pull request in Gitea can run tests, builds and deployments on your own hardware, without a hosted CI service.

Use this stack when you already run Gitea (see the Gitea stack in this series) and want automated builds on your own machines. It is a good fit for small teams that deploy with Compose and want the pipeline to run where the code lives. Do not use it on the same machine as production data without thinking about isolation, because pipeline steps run arbitrary code from your repositories, and the agent has access to the Docker daemon. Do not open registration: set WOODPECKER_OPEN to false and grant access to named users. Do not expose the gRPC port between server and agent to the internet; it is meant for the private network. If your team needs strict isolation, use a separate virtual machine for the agent or a Kubernetes backend.

docker-compose.yml

services:
  woodpecker-server:
    image: woodpeckerci/woodpecker-server:v2.7.0
    restart: unless-stopped
    environment:
      WOODPECKER_HOST: ${WOODPECKER_HOST}
      WOODPECKER_GITEA: "true"
      WOODPECKER_GITEA_URL: ${GITEA_URL}
      WOODPECKER_GITEA_CLIENT: ${WOODPECKER_GITEA_CLIENT}
      WOODPECKER_GITEA_SECRET: ${WOODPECKER_GITEA_SECRET}
      WOODPECKER_AGENT_SECRET: ${WOODPECKER_AGENT_SECRET}
      WOODPECKER_ADMIN: ${WOODPECKER_ADMIN}
      WOODPECKER_OPEN: "false"
    ports:
      - "127.0.0.1:${WOODPECKER_HTTP_PORT}:8000"
    expose:
      - "9000"
    volumes:
      - woodpecker_server_data:/var/lib/woodpecker

  woodpecker-agent:
    image: woodpeckerci/woodpecker-agent:v2.7.0
    restart: unless-stopped
    command: agent
    environment:
      WOODPECKER_SERVER: woodpecker-server:9000
      WOODPECKER_AGENT_SECRET: ${WOODPECKER_AGENT_SECRET}
      WOODPECKER_MAX_WORKFLOWS: "1"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - woodpecker-server

volumes:
  woodpecker_server_data:

.env

.env
# Public HTTPS address of Woodpecker. It must match the OAuth callback.
WOODPECKER_HOST=https://CHANGE_ME_ci.example.com

# Host port for the web UI, bound to 127.0.0.1
WOODPECKER_HTTP_PORT=8000

# Public HTTPS address of your Gitea instance
GITEA_URL=https://CHANGE_ME_git.example.com

# OAuth application created in Gitea (Settings, Applications)
WOODPECKER_GITEA_CLIENT=CHANGE_ME_oauth_client_id
WOODPECKER_GITEA_SECRET=CHANGE_ME_oauth_client_secret

# Shared secret between server and agent. Generate with: openssl rand -hex 32
WOODPECKER_AGENT_SECRET=CHANGE_ME_openssl_rand_hex_32

# Gitea username that becomes the Woodpecker administrator
WOODPECKER_ADMIN=CHANGE_ME_gitea_username

Start and verify

Shell
# 1. Generate the agent secret and paste it into .env
openssl rand -hex 32

# 2. In Gitea, create an OAuth application with the redirect URI
#    https://CHANGE_ME_ci.example.com/authorize and copy its client ID and secret into .env

# 3. Validate and start
docker compose config --quiet
docker compose up -d
docker compose ps
docker compose logs --tail=50 woodpecker-server woodpecker-agent

# 4. Verify the server health endpoint and the agent connection
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:8000/healthz
docker compose logs woodpecker-agent | grep -i "connected\|error" | tail -n 5

Sign in through the Woodpecker web UI with the Gitea account named in WOODPECKER_ADMIN, enable a test repository, add a .woodpecker.yml with a single step that prints a message, and push a commit to trigger the first pipeline.

Production checklist

  • Run the agent on a dedicated machine when possible. The Docker socket mount gives every pipeline step root-level power over that host.
  • Keep WOODPECKER_OPEN set to false, and enable only the repositories that need CI.
  • Do not allow privileged pipeline steps for repositories you do not fully trust, and do not trust forks or pull requests from unknown contributors.
  • Generate WOODPECKER_AGENT_SECRET with a cryptographic random generator and keep it out of the Git repository.
  • Publish only the web UI on 127.0.0.1 and place an HTTPS proxy in front. Do not publish port 9000, which is used between the server and the agents.
  • Store deployment credentials in the Woodpecker secrets store, restricted to specific repositories and events, rather than in repository files.
  • Set WOODPECKER_MAX_WORKFLOWS to a value that fits the CPU and memory of the agent machine.
  • Back up woodpecker_server_data, which holds the database, and schedule docker system prune on the agent so old pipeline images do not fill the disk.
  • Pin the v2.7.0 images. Minor versions can change the pipeline syntax, so test a new version on a sample repository first.

Common problems

  • Symptom: Login loops, or the browser shows “redirect_uri mismatch” from Gitea. Cause: The OAuth callback in Gitea does not equal WOODPECKER_HOST followed by /authorize. Fix: Edit the Gitea OAuth application so the redirect URI matches exactly, including https and the trailing path.
  • Symptom: The agent logs connection errors to woodpecker-server:9000. Cause: The two services use different WOODPECKER_AGENT_SECRET values, or the server is still starting. Fix: Make the values identical in .env, then run docker compose up -d and check the logs again.
  • Symptom: Pipelines stay in the pending state. Cause: No agent is connected, or the WOODPECKER_MAX_WORKFLOWS limit is already reached. Fix: Check docker compose ps for the agent and raise the limit only if the machine has spare capacity.
  • Symptom: The server cannot list repositories from Gitea. Cause: GITEA_URL points at localhost, which inside a container is the container itself. Fix: Use the public HTTPS address of Gitea, or the Docker network name if both run in the same Compose project.
  • Symptom: Pipeline steps fail with “permission denied” on the Docker socket. Cause: The socket is missing from the agent volumes, or the host applies an SELinux or AppArmor policy that blocks it. Fix: Confirm the socket line in docker-compose.yml and check the host security logs.

Variations

  • Kubernetes backend: Run pipeline steps as Kubernetes pods instead of Docker containers, which keeps the workloads in a cluster with its own isolation. Follow the Woodpecker backend documentation for the required settings.
  • Remote agents: Add agents on separate machines with the same secret and point WOODPECKER_SERVER at the server’s gRPC address over a private network or VPN, using TLS if the traffic crosses an untrusted network.
  • GitHub or GitLab: Replace the WOODPECKER_GITEA variables with the matching forge settings from the Woodpecker documentation, and keep the same agent design.

Questions

Why does the agent need the Docker socket?

Woodpecker runs each pipeline step in its own container, and the Docker backend starts those containers through the socket. That access is equivalent to root on the host, so run the agent on a dedicated machine.

What is WOODPECKER_AGENT_SECRET for?

It is the shared password between the server and each agent. Generate it with openssl rand -hex 32, put the same value in both services, and never commit it to a repository.

Why does the OAuth login fail with redirect_uri mismatch?

The Gitea OAuth application must use the callback address WOODPECKER_HOST followed by /authorize. Any difference in scheme, domain or path causes this error.

Can Woodpecker use GitHub or GitLab instead of Gitea?

Yes. Woodpecker supports several forges. Replace the Gitea variables with the matching forge variables from the Woodpecker documentation.

Adapt this stack

Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.

Open in builder
  • Caddy 2 Reverse Proxy + Static Web Server

    Caddy 2 in Docker Compose: serve a static site, proxy /api to a backend and get automatic HTTPS on a real domain. Pinned images and .env configuration.

    • caddy
    • whoami
    Difficulty: Beginner
  • Gitea Git Server with PostgreSQL 16

    Self-hosted Gitea with PostgreSQL 16 in Docker Compose: web Git hosting, SSH on port 2222, a healthcheck-gated database start and persistent volumes.

    • gitea
    • db
    Difficulty: Intermediate
  • Loki, Promtail and Grafana Log Stack

    Collect Linux host logs with Loki and Promtail in Docker Compose and query them in Grafana. Pinned images, persistent volumes and a localhost-only Grafana port.

    • loki
    • promtail
    • grafana
    Difficulty: Intermediate
  • Portainer CE Web UI for Docker Management

    Run Portainer CE in Docker Compose as a web UI for containers, images and volumes. Bound to localhost on HTTPS 9443, with persistent data and a pinned image.

    • portainer
    Difficulty: Intermediate

Browse more Infrastructure & Monitoring stacks or the full library.