Background script that checks Docker containers running on the host and creates their Caddy reverse proxy config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Max Mehl 3334af20b3
add REUSE status badge
4 months ago
LICENSES make REUSE compliant 6 months ago
caddy_host_templates create a directory with some proposed caddy host templates 4 months ago
logrotate.d make REUSE compliant 6 months ago
systemd make REUSE compliant 6 months ago
.gitignore add simple ansible deployment 6 months ago add REUSE status badge 4 months ago
config.cfg.sample update and document defaults 4 months ago update and document defaults 4 months ago
install.yml fix REUSE compliance 4 months ago


REUSE status

This tool automatically generates configuration files for reverse proxy functionality between Caddy and Docker containers. It provides something like auto-discoverability, so if a new Docker container is spun up, it will be scanned sooner or later for specific labels. If they match the tool's expectations, Caddy configuration for this host will be generated.

Container configuration

To allow caddy to be a reverse proxy for a docker container, and docker2caddy find the necessary information, you'll have to add labels to the docker container. In a docker-compose.yml file, this could look like the following:

  container_name: webservice
  image: httpd:2.4
  restart: always
    - "12345:8080"
  labels: ""
    proxy.port: "12345"
    proxy.host_alias: ","

In this example, the exposed port in the Docker container is 8080, and we map it to port 12345 on the host.

The labels can be configured in config.cfg.



To deploy docker2caddy on a host, these files should be handled.

  • One of the caddy config templates in caddy_host_templates_/ or an own one -> /etc/docker2caddy/caddy_host.j2 (basic.j2 is the simplest)
  • config.cfg -> /etc/docker2caddy/ (rename from .sample)
  • -> /usr/local/bin/docker2caddy
  • logrotate.d/docker2caddy -> /etc/logrotate.d/ (must be root:root, 0644)
  • systemd/docker2caddy.service -> /etc/systemd/system/


Within caddy, you need to import the new directory in which the configs are created:

import /etc/caddy/docker2caddy/*


Docker rootless

If you have a rootless Docker setup, you should set the DOCKER_HOST config variable, e.g. to unix:///run/user/1001/docker.sock. Please note that a system-wide environment (not only from .bashrc) or one that is directly called with the program (e.g. DOCKER_HOST=foobar or a prior export) always takes precedence.

Logs and Debug

Logging will take place in /var/log/docker2caddy.log. Logs are rotated daily, and kept back for the last 7 days.

Also check systemd's journal: journalctl -u docker2caddy