Unable to initialise Caddy in Docker

1. Output of caddy version:

Can’t get this as Docker isn’t launching: caddy:2.6.2-builder-alpine

2. How I run Caddy:

Trying to run within docker-compose

a. System environment:

Docker: caddy:2.6.2-builder-alpine

b. Command:

docker-compose up --build

c. Service/unit/compose file:

version: "3.9"


    container_name: caddy
    image: caddy:2.6.2-builder-alpine
    restart: unless-stopped
      - "80:80"
      - "443:443"
      - API_HOST=
      - API_PORT=8080
      - caddy_logging:/var/log/
      - caddy_data:/data
      - ./Caddyfile:/etc/caddy/Caddyfile


d. My complete Caddy config:

    email test@realizesec.com
    http_port    80
	#https_port   443
    log {
		output file /var/log/access.log {
		roll_size 1gb
		roll_keep 5
		roll_keep_for 720h
		format  json
		level   INFO

realizesec.com www.realizesec.com api.realizesec.com {

    header {
        Strict-Transport-Security max-age=31536000;
        X-Content-Type-Options nosniff
        X-Frame-Options DENY
        Referrer-Policy no-referrer-when-downgrade
        Content-Security-Policy: default-src 'self'

    handle /api/* {
		reverse_proxy {$API_HOST}:{$API_PORT} 

3. The problem I’m having:

I am trying to run Caddy via docker-compose but it is exiting with code 0 immediately after attaching. So far as I can tell my setup is valid.


This text will be hidden

4. Error messages and/or full log output:

Paste logs/commands/output here.
➜  janusproxy git:(caddy_migration) ✗ docker-compose up --build
caddy is up-to-date
Attaching to caddy
caddy exited with code 0

5. What I already tried:

I have tried the following:

  1. Adding and removing HTTPS
  2. Switching environment variable formatting, i.e. {$API_HOST} vs {env.AP}
  3. Creating external networks
  4. Changing the reverse_proxy target to available hosts on the public internet
  5. Trimming down the Caddyfile to only include reverse_proxy host:port
  6. Emulating ’ Docker Compose example’ example shown in Docker hub

6. Links to relevant resources:


The builder variant is meant for building (compiling) Caddy, not for actually running Caddy.

Well I feel like an idiot. Thanks for pointing this out

1 Like

No worries! :blush:

This topic was automatically closed after 30 days. New replies are no longer allowed.