Having issues setting up Caddy v2 with PHP-FPM in Docker

1. Caddy version: v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I installed, and run Caddy: Docker builder

a. System environment: Docker

b. Command:

caddy run --config docker/Caddyfile

c. Service/unit/compose file:

FROM caddy:builder as builder
RUN xcaddy build \
    --with github.com/baldinof/caddy-supervisor

FROM php:8.1-fpm-alpine

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY --from=builder /usr/bin/caddy /usr/bin/caddy

RUN apk add --no-cache autoconf bash openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev vim && \
 docker-php-ext-install bcmath intl opcache zip sockets && \
 apk del --purge autoconf g++ make && \
 mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

WORKDIR /usr/src/app

COPY . .

RUN composer install \
    --no-dev \
    --optimize-autoloader \
    --no-plugins \
    --prefer-dist \
    --no-progress \


RUN caddy validate --config=docker/Caddyfile  \
    && cp docker/php-fpm.conf /usr/local/etc/php-fpm.d/zz-docker.conf  \
    && chmod -R 777 bootstrap/cache storage

EXPOSE 80 443

CMD ["caddy", "run", "--config", "docker/Caddyfile"]

d. My complete Caddy config:

    log {
        output stdout
        format console
        level DEBUG
    supervisor {
        php-fpm {
            restart_policy always
            redirect_stdout stdout
            redirect_stderr stderr

*:{$PORT} {
    root * /usr/src/app/public
    php_fastcgi /var/run/php-fpm.sock {
        dial_timeout 60s

3. The problem I’m having:

I get a blank white page when viewing the site after running the Docker container

4. Error messages and/or full log output:

twm_1  | {"level":"info","ts":1674692610.1530328,"msg":"using provided configuration","config_file":"docker/Caddyfile","config_adapter":""}
twm_1  | {"level":"warn","ts":1674692610.154689,"msg":"Caddyfile input is not formatted; run the 'caddy fmt' command to fix inconsistencies","adapter":"caddyfile","file":"docker/Caddyfile","line":2}
twm_1  | {"level":"info","ts":1674692610.1551828,"msg":"redirected default logger","from":"stderr","to":"stdout"}
twm_1  | 2023/01/26 00:23:30.157        INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//[::1]:2019", "//", "//localhost:2019"]}
twm_1  | 2023/01/26 00:23:30.158        WARN    http    server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "srv0", "http_port": 80}
twm_1  | 2023/01/26 00:23:30.165        DEBUG   supervisor      module provisioned      {"supervisors": [{"Options":{"Command":"php-fpm","Replica":0,"Args":[],"Dir":"","Env":[],"RedirectStdout":{"type":"stdout"},"RedirectStderr":{"type":"stderr"},"RestartPolicy":"always","TerminationGracePeriod":10000000000,"User":""}}]}
twm_1  | 2023/01/26 00:23:30.165        DEBUG   http    starting server loop    {"address": "[::]:80", "tls": false, "http3": false}
twm_1  | 2023/01/26 00:23:30.165        INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
twm_1  | 2023/01/26 00:23:30.165        DEBUG   supervisor      module started
twm_1  | 2023/01/26 00:23:30.166        INFO    autosaved config (load with --resume flag)      {"file": "/root/.config/caddy/autosave.json"}
twm_1  | 2023/01/26 00:23:30.167        INFO    serving initial configuration
twm_1  | 2023/01/26 00:23:30.169        INFO    supervisor      process started {"command": ["php-fpm"], "replica": 0, "pid": 9}
twm_1  | 2023/01/26 00:23:30.178        INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc00041d260"}
twm_1  | 2023/01/26 00:23:30.178        INFO    tls     cleaning storage unit   {"description": "FileStorage:/root/.local/share/caddy"}
twm_1  | 2023/01/26 00:23:30.178        INFO    tls     finished cleaning storage units
twm_1  | [26-Jan-2023 00:23:30] NOTICE: fpm is running, pid 9
twm_1  | [26-Jan-2023 00:23:30] NOTICE: ready to handle connections

5. What I already tried:

I’ve rewritten the setup about 3 times at this point, it was working before with Caddy v1 but now I’ve swapped to Caddy v2 it does not work. I’ve tried restarting PHP-FPM and Caddy and I’ve tried a multitude of different configs and I really do not understand why this does not work.

6. Links to relevant resources:

You also need file_server.

Caddy doesn’t enable a file server by default, so you need to add that directive for Caddy to serve static files.

Since you’re using a different base image, you’ll need to do some additional configuration to make sure Caddy is properly set up. See the things in the base image:

  • Make sure ca-certificates and mailcap are installed as well (not sure if the PHP image comes with them).

  • Make sure to set XDG_CONFIG_HOME and XDG_DATA_HOME so that Caddy’s storage is in a predictable place

  • Make sure to set up a volume for Caddy’s storage so that you don’t lose your issued certs and keys when running in production.