I'm using https://github.com/dunglas/symfony-docker Symfony images with caddy and frankephp for my app, but now I need to add another app with the same image, so to do so I considered moving docker-compose to one level higher, like
backend/
compose.yaml
catalog/
admin/
now my compose file looks like this:
services:
catalog:
image: ${IMAGES_PREFIX:-}app-php
build:
context: ./catalog
target: frankenphp_dev
volumes:
- ./catalog:/app
- ./catalog/frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
- ./catalog/frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
restart: unless-stopped
environment:
SERVER_NAME: ${SERVER_NAME:-localhost}, php:80
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|php$$
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}&charset=${POSTGRES_CHARSET:-utf8}
# The two next lines can be removed after initial installation
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
STABILITY: ${STABILITY:-stable}
volumes:
- caddy_data:/data
- caddy_config:/config
ports:
# HTTP
- target: 80
published: 8001
protocol: tcp
# HTTPS
- target: 443
published: 441
protocol: tcp
# HTTP/3
- target: 443
published: 441
protocol: udp
admin:
image: ${IMAGES_PREFIX:-}app-php
build:
context: ./admin
target: frankenphp_dev
volumes:
- ./admin:/app
- ./admin/frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
- ./admin/frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
restart: unless-stopped
environment:
SERVER_NAME: ${SERVER_NAME:-localhost}, php:80
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|php$$
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}&charset=${POSTGRES_CHARSET:-utf8}
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
STABILITY: ${STABILITY:-stable}
volumes:
- caddy_data:/data
- caddy_config:/config
ports:
# HTTP
- target: 80
published: 8002
protocol: tcp
# HTTPS
- target: 443
published: 442
protocol: tcp
# HTTP/3
- target: 443
published: 442
protocol: udp
database:
image: postgres:15-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
POSTGRES_USER: ${POSTGRES_USER:-app}
volumes:
- database_data:/var/lib/postgresql/data:rw
volumes:
caddy_data:
caddy_config:
database_data:
as you can see I specified different ports for each app 8001 and 8002 and different https ports 441 and 442.
In both app I have identical Caddyfile:
{
{$CADDY_GLOBAL_OPTIONS}
frankenphp {
{$FRANKENPHP_CONFIG}
}
order vulcain after reverse_proxy
order php_server before file_server
}
{$CADDY_EXTRA_CONFIG}
{$SERVER_NAME:localhost} {
log {
format filter {
wrap console
fields {
uri query {
replace authorization REDACTED
}
}
}
}
root * /app/public
encode zstd gzip
vulcain
{$CADDY_SERVER_EXTRA_DIRECTIVES}
header ?Permissions-Policy "browsing-topics=()"
php_server
}
I am able to run containers by running docker-compose up -d but I'm not able to open app URLs, for example, localhost:8001/filters, I'm getting the error Error: connect ECONNREFUSED ::1:443
but when only one app is running all good.
I'm new to Caddy, but I think I need to set up some rever-proxy on top of my apps?