On this pagePush or pull
GitOps means one rule: the Git repository describes what should run, and something on the server makes reality match it. In the Kubernetes world, Argo CD and Flux do that job. Most small teams do not run Kubernetes, though. They run Docker Compose on one to ten servers, and they still want "merge the pull request, and production updates itself." This guide covers the tools that bring that workflow to Compose, and the simple version you can build in twenty lines.
Push or pull
There are two ways to get a commit onto a server.
| CI pushes | Server pulls | |
|---|---|---|
| How | A pipeline runs docker compose up -d over SSH |
An agent on the server watches the repository |
| Credentials | CI holds an SSH key to every server | Each server holds a read-only repository token |
| Firewall | SSH must be reachable from CI | Only outbound HTTPS, plus an optional webhook |
| Drift | Fixed only at the next deploy | Corrected on every sync |
| Audit trail | Pipeline logs | Git history plus agent logs |
Pulling is what the term GitOps usually means. Its biggest advantage is security: no external system holds keys that can run commands on your servers, and a compromised CI runner cannot reach production directly.
doco-cd: a small agent built for Compose
doco-cd is an Apache 2.0 tool written in Go that deploys and updates Compose projects and Swarm stacks from Git. It runs as one container with a minimal distroless image, and it can be triggered by polling on a schedule or by webhooks from GitHub, GitLab, Gitea and Forgejo. It also handles SOPS-encrypted secrets and external secret providers, deploys to several hosts through Docker contexts, sends notifications and exposes Prometheus metrics.
The deploy repository
Keep deployment files in their own repository, separate from application code. Each stack gets a compose.yaml and a .doco-cd.yaml at the root, or in a subdirectory you configure:
name: shop
reference: main
compose_files:
- compose.yaml
remove_orphans: true
remove_orphans deletes containers for services you removed from the file, which is what you want when Git is the source of truth.
Running the agent
This version polls every three minutes, so it needs no published port at all:
services:
doco-cd:
image: ghcr.io/kimdre/doco-cd:latest
restart: unless-stopped
environment:
TZ: Etc/UTC
GIT_ACCESS_TOKEN: ${GIT_ACCESS_TOKEN}
POLL_CONFIG: |
- url: https://github.com/example/deploy-shop.git
reference: main
interval: 180
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- data:/data
cap_drop:
- ALL
volumes:
data:
Put GIT_ACCESS_TOKEN in a .env file readable only by root, and give the token read access to the deploy repository and nothing else. If your Git server is not github.com, the GIT_AUTH_DOMAINS setting tells doco-cd which hosts may receive the token.
For instant deploys, switch to webhooks. doco-cd listens on /v1/webhook and checks the signature against WEBHOOK_SECRET. The project recommends publishing its port only to a trusted HTTPS reverse proxy, for example 127.0.0.1:8080:80 behind Caddy, and keeping the metrics port private.
Komodo: GitOps with a dashboard
Komodo is a GPL-3.0 platform made of a central Core, which provides the web interface and API, and a small Periphery agent on each server. Its Stacks deploy Compose files from a Git repository, and each Stack exposes webhook endpoints such as /deploy and /refresh that your Git server can call on push.
Komodo goes further with Resource Syncs: servers, stacks and build definitions declared in TOML files inside a repository. Push a change to those files and Komodo computes the difference, then applies it either after manual confirmation in the UI or automatically through the sync webhook. It suits teams that want both GitOps and a place to click when something breaks.
Arcane Git Sync
If you already use Arcane as your Docker UI, its Git Sync feature keeps a project's Compose file in step with a repository, with lifecycle hooks around deployments. That avoids a second tool when one or two stacks are all you need. The Arcane setup guide covers installing and securing it.
The twenty-line version: a script and a timer
For a single server and a single stack, a script plus a systemd timer is enough, easy to audit and free of new dependencies. Save this as /usr/local/bin/compose-sync and make it executable:
#!/usr/bin/env bash
set -euo pipefail
cd /srv/shop
git fetch --quiet origin main
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
git reset --hard origin/main
docker compose pull --quiet
docker compose up -d --remove-orphans
logger -t compose-sync "deployed $(git rev-parse --short HEAD)"
fi
Then add /etc/systemd/system/compose-sync.service:
[Unit]
Description=Sync the shop stack from Git
[Service]
Type=oneshot
ExecStart=/usr/local/bin/compose-sync
And /etc/systemd/system/compose-sync.timer:
[Unit]
Description=Run compose-sync every two minutes
[Timer]
OnBootSec=1min
OnUnitActiveSec=2min
[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now compose-sync.timer
journalctl -t compose-sync # deployment history
The git reset --hard is deliberate: local edits on the server are drift, and drift gets overwritten. Clone the repository with a read-only deploy key, never with your personal credentials. On CloudSat, the clone and the two units can go into a startup script, so a replacement server joins the workflow on its first boot.
Staging and production from one repository
Most teams want a change to reach staging first. Keep one directory per environment in the deploy repository, each with its own Compose file and agent settings:
deploy-shop/
staging/compose.yaml
production/compose.yaml
The staging server syncs staging/ from main; the production server syncs production/ from a protected production branch. Promoting a release then means a pull request into production that sets the image tag already tested in staging/compose.yaml in production/compose.yaml too. It is a little more typing than a shared file with overrides, but anyone can read exactly what runs where, and a broken staging change never touches production.
Guardrails that make it safe
- Pin image versions. A Compose file that says
image: shop:latestis not a description of what runs; it is a pointer that moves. Use explicit tags or digests, and let a pull request bump them. - Keep secrets out of plain text. Encrypt them with SOPS and an age key, or pull them from a secret manager. A deploy repository is copied to every server it targets.
- Protect the branch. Require an approved pull request before anything lands on the branch the servers follow. Whoever can push there can run code on production.
- Roll back with Git.
git reverton the deploy repository is the rollback procedure, and it leaves a record. Database migrations are the exception: they need their own backward-compatible plan. - Add health checks. A
healthcheckin Compose and a restart policy let you see a bad deploy quickly instead of serving errors silently.
A note on image auto-updaters: Watchtower, long the default tool for updating containers automatically, was archived in December 2025. Auto-updating images is a different model anyway. GitOps updates only what a reviewed commit says, which is the point.
FAQ
Does this work with private repositories?
Yes. doco-cd uses an access token, Komodo stores Git credentials per provider, and the script approach uses an SSH deploy key. In every case, grant read-only access to the deploy repository only.
Do I need Docker Swarm?
No. All the options here work with plain Compose. doco-cd and Komodo can also manage Swarm stacks if you later spread services across nodes.
How do I deploy to several servers?
Give each server its own directory or branch in the deploy repository and run an agent per server, or use doco-cd's Docker contexts and Komodo's Periphery agents to drive several hosts from one place.
Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.




