Caddy in Docker - unknown directive errors

1. The problem I’m having:

I am trying to add a global response to my caddy server, and in adding a new block, I am getting the following error:-

{"level":"info","ts":1691501378.77935,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
Error: adapting config using caddyfile: /etc/caddy/Caddyfile:10: unrecognized directive: close

2. Error messages and/or full log output:

{"level":"info","ts":1691501378.77935,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
Error: adapting config using caddyfile: /etc/caddy/Caddyfile:10: unrecognized directive: close

3. Caddy version:

Using the caddy:2.7.2 image from docker hub:-

❯ docker compose exec caddy caddy version      
v2.7.2 h1:QqThyoyUFAv1B7A2NMeaWlz7xmgKqU49PXBX08A+6xg=

4. How I installed and ran Caddy:

I ran it within Docker (with Compose) using the following Dockerfile:-

FROM caddy:builder AS builder

RUN xcaddy build --with github.com/caddy-dns/cloudflare@a9d3ae2690a1d232bc9f8fc8b15bd4e0a6960eec

FROM caddy:2.7.2

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

a. System environment:

Host is Debian 12 x86_64.
Running within docker, latest released version.

b. Command:

See the above Dockerfile.

c. Service/unit/compose file:

FROM caddy:builder AS builder

RUN xcaddy build --with github.com/caddy-dns/cloudflare@a9d3ae2690a1d232bc9f8fc8b15bd4e0a6960eec

FROM caddy:2.7.2

COPY --from=builder /usr/bin/caddy /usr/bin/caddy
services:
  caddy:
    ports:
      - 443:443
      - 80:80
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./caddyfiles/:/etc/my_caddy_files/
      - /home/penumbra/images/:/etc/images/:ro
      - /home/penumbra/audio/:/etc/audio/:ro
      - /home/penumbra/static/:/etc/static/:ro
      - caddy_data:/data
      - caddy_config:/config
    container_name: "caddy"
    env_file: .env
    build: .
    networks:
      main:

volumes:
  caddy_data:
  caddy_config:

networks:
  main:
    name: main
    external: true

d. My complete Caddy config:

{
	email umbra@abstractumbra.dev
	acme_dns cloudflare {env.CF_TOKEN}
	# dns cloudflare {env.CF_TOKEN}
    # resolvers 1.1.1.1
    debug
}
import /etc/my_caddy_files/*.caddy

respond /robots.txt "User-Agent: *\nDisallow: /" 200 {
    close
}

abstractumbra.dev:443 {
	redir https://about.abstractumbra.dev/
}

:80, :443 {
	respond 404
}

5. Links to relevant resources:

Additional context:-
The response body also did not recognize the body directive within it either.
I assumed these were present in my version as they are outlined in the documentation

Ah, my mistake. It needed to be within a address/location block, like the :80, :443 at the end.

It’s called a “site block”. See Caddyfile Concepts — Caddy Documentation

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