How can I run caddy:builder docker image?

1. The problem I’m having:

I need to use xcaddy to custom some modules. I tried to use a caddy docker image, which includes develop environmnent.
I used the same Caddyfile, I can run it using the docker image caddy:lastest, but the docker image caddy:builder and caddy:builder-alpine will stop.

2. Error messages and/or full log output:

sorry, docker logs ID shows nothing.

3. Caddy version:

the docker image → latest
the docker image → builder

4. How I installed and ran Caddy:

a. System environment:

b. Command:

c. Service/unit/compose file:

I used this compose.yaml

services:
  webserver:
    container_name: WebServer
    image: caddy:latest
    restart: always
    network_mode: bridge
    ports:
      - 52332:80
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile

and I modified image, if caddy:builder.

d. My complete Caddy config:

My Caddyfile:

www.google.cn:80 {
	redir https://www.google.com{uri}
}

5. Links to relevant resources:

You didn’t tell your docker-compose to use your custom Dockerfile. You need to use the build: field to do that.

It’s mentioned here: Keep Caddy Running — Caddy Documentation

1 Like

No, I told docker-compose to use builder image.
I tried:
image: caddy:latest, the docker can run
image: caddy:builder, the docker well stop
Notice: I used the same Caddyfile, the only difference just is the image

you means below?

services:
  webserver:
    container_name: WebServer
    build: caddy:builder
    restart: always
    network_mode: bridge
    ports:
      - 52332:80
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile

No. You need to make a file named Dockerfile next to your compose.yml and then use build: . (the . means “this current directory”, i.e. look for the Dockerfile here). See Build from source — Caddy Documentation for how to write the Dockerfile.

1 Like