I was trying to do something like this. However, I may give your command: option a try.
version: "3"
services:
caddy:
build:
context: .
dockerfile: Dockerfile
args:
--with github.com/caddy-dns/cloudflare \
--with github.com/kirsch33/realip \
--with github.com/greenpau/caddy-security \
--with github.com/hslatman/caddy-crowdsec-bouncer
image: caddy/caddy:builder-alpine
container_name: caddy
ports:
- 80:80
- 443:443
volumes:
- /docker/caddy/config:/config