dockr is a modular Bash toolkit for provisioning secure Docker hosts on Ubuntu, managing TLS certificates, installing Traefik, orchestrating Traefik routes, and wrapping docker-compose deployments. The CLI follows the architecture described in SPEC.md and aims to be dependency-light while remaining automation-friendly for CI/CD pipelines.
- Ubuntu 20.04 LTS or newer with
systemdand network access to Docker/ACME repositories. - Root or sudo privileges when running
dockr(certificate generation, firewall rules, and system services require it). jqand other base packages are installed automatically bydockr init, but on a development workstation you may also wantshellcheckfor linting.
Clone the repository onto the target host (or bundle it via configuration management) and add bin/ to your PATH:
git clone https://example.com/dockr.git
cd dockr
sudo install -m 755 bin/dockr /usr/local/bin/dockrYou can also execute from the repo directly using sudo ./bin/dockr ....
-
Bootstrap a host
sudo dockr init \ --host prod01 \ --addr 203.0.113.10 \ --domain example.com \ --email [email protected] \ --with-traefik
This installs Docker (remote API on TCP/2376 with TLS), configures UFW, generates certificates, and persists a host profile to
~/.dockr/hosts/prod01.yml. -
Install Traefik
sudo dockr traefik install --host prod01 --dashboard-user admin --dashboard-password changeme
Traefik configuration and ACME storage are written under
/opt/traefik. -
Define routes
sudo dockr route add \ --host prod01 \ --name app \ --rule "Host(`app.example.com`)" \ --service app \ --service-url http://app:8080Route definitions live at
~/.dockr/routes/prod01.ymland are consumed by Traefik's file provider. -
Deploy a compose stack
sudo dockr deploy up --compose-file deploy/docker-compose.yml --project prod01 --pull
Wraps
docker composewith consistent flags and project naming suitable for CI. -
Check health
dockr health dockr health --json
Displays Docker service status, UFW state, Traefik stack status, and TLS expiry.
dockr init maintains state under ~/.dockr/ (configurable via DOCKR_STATE_DIR). Important paths:
hosts/<name>.yml— persisted data: address, domain, email, enabled features.routes/<name>.yml— Traefik file-provider configuration for the host.logs/— room for future per-run logs.backups/— archives created bydockr cert docker backup./root/docker-certs/— Docker TLS bundle (CA, server, client certs/keys).
Use dockr cert docker info/rotate/backup to inspect or manage TLS assets; these commands read profile defaults when --host is provided.
Bootstrap an Ubuntu host with Docker, TLS, firewall rules, and optional extras.
Key flags:
--host <name>(required) — logical host identifier used for profiles.--addr <ip>— primary IP for SANs; defaults to first non-loopback address.--domain <fqdn>/--email <address>— populate host profile and Traefik defaults.--remote-port <port>— Docker TLS port (default 2376).--no-remote-apidisables TCP listener.--sshkeymgr— install Hetznersshkeymgrhelper and cron job.--with-traefik— mark host with Traefik feature (install separately viadockr traefik install).--tls-days <n>— certificate validity window (default 365).--dry-run— log actions without executing (best-effort).
Manage Docker TLS lifecycle.
info— display subject, issuer, validity, fingerprint of server certificate.rotate— regenerate server/client certs while preserving the CA; restarts Docker.- Supports
--host,--addr,--domain,--client-name,--daysoverrides.
- Supports
backup— archive/root/docker-certsinto~/.dockr/backups/docker-certs-<timestamp>.tar.gz.
Install or manage Traefik reverse proxy assets under /opt/traefik.
install— render static/dynamic configs, configure ACME, optional dashboard basic auth, create Docker networktraefik_proxy, and rundocker compose up -d.- Flags:
--host,--email,--staging,--image,--dashboard-user,--dashboard-password.
- Flags:
status— rundocker compose psfor the Traefik stack.remove—docker compose downwithout deleting configs.
Operate on Traefik file-provider YAML.
list— tabular output of routers/rules/services.add— create router/service entries (defaults toentryPoints: websecure).remove— delete router and associated service.edit— open route file in$EDITOR(defaults tonano).
Wrapper around docker compose for consistent deployments.
up—docker compose up -d; supports--pull,--remove-orphans,--project,--compose-file.down—docker compose downwith same targeting options.
Print summary of Docker, UFW, Traefik status, and Docker TLS expiry. With --json, emits machine-readable output (useful in CI).
templates/gitlab-ci.yml demonstrates how to materialize TLS certificates from CI variables, authenticate to your registry, and deploy via docker-compose. To adopt dockr in GitLab:
- Add a deploy job stage pulling the repo (or vendored artifact).
- Materialize TLS certs under
$DOCKER_CERT_PATHas shown. - Run
dockr health --jsonto fail fast if the host is unhealthy. - Use
dockr deploy up --compose-file deploy/docker-compose.yml --project $CI_ENVIRONMENT_SLUG --pull. - Optionally export route files and apply them with
dockr routecommands or manage via Git.
Use templates/github-actions.yml as a starting point for GitHub Actions. It checks out the repo, installs prerequisites, materializes TLS certificates from secrets, runs a health check, and triggers dockr deploy up.
For GitHub Actions, follow that pattern with sudo within the runner and secrets for PEM content.
- Run
shellcheckacross the codebase:shellcheck bin/dockr lib/*.sh commands/*.sh. - Static analysis:
bash -non scripts to catch syntax errors. - Manual verification: execute
dockr inittwice on the same host to confirm idempotency, validate Traefik routes, and inspect TLS expiry dates before/after rotation. - Add integration or unit tests as you expand functionality;
batsor Python-based harnesses are good options when mocking system calls.
- Docker daemon fails to restart: Check
/var/log/syslogand/etc/docker/daemon.jsonfor JSON syntax.dockrvalidates viajqwhen available. - Traefik ACME issues: Inspect
/opt/traefik/loganddocker logs traefik. Verify DNS records and that ports 80/443 are reachable. - UFW blocks remote API: Ensure
dockr initran with remote API enabled or manually runufw allow 2376/tcp. - Certificates not trusted in CI: Download
~/.dockr/backupsarchive or usedocker cert docker rotate --client-name cito generate dedicated client bundles.
Review AGENTS.md for contributor guidelines, coding style, and pull request expectations. Always update SPEC.md when new modules or behaviours diverge from the architecture plan.