By running /usr/bin/caddy run --config /etc/Caddyfile in a Docker container
a. System environment:
Docker (php:7.4-fpm-alpine)
b. Command:
/usr/bin/caddy run --config /etc/Caddyfile
c. Service/unit/compose file:
d. My complete Caddyfile or JSON config:
# We are behind a reverse proxy so using http here.
0.0.0.0:80
# Define our root path
root * /var/www
# Point all PHP requests to an upstream socket, served by php-fpm
php_fastcgi 127.0.0.1:9000
# Enable access logging
log
# Serve static files
file_server
# Enable gzip compression (and zstd)
encode zstd gzip
3. The problem I’m having:
In the Caddy v1, I could do this:
# Point all PHP requests to an upstream socket, served by php-fpm
# Start php-fpm before the server starts listening
fastcgi / 127.0.0.1:9000 php
on startup php-fpm
However, I cannot find anything back in the Caddy v2 docs about the “on startup”.
Is there a way to startup the php-fpm process in Caddyv2? Am I overlooking something in the docs? Or should I make a Docker entrypoint script that starts up php-fpm first, and then runs caddy run?
@tweeniev2, Yeah well… I use Dokku (Dokku - The smallest PaaS implementation you've ever seen) to easily deploy some containers of my sideprojects. It’s like Heroku. But it installs an Nginx reverse proxy in front of the Docker containers… Nginx handles the Letsencrypt certificate automatically. But I like Caddy for the simplicity in combination with my php app Someday I’ll entirely use Caddy probably. The documentation mentions Caddy so I guess it’s possible in the future: Dokku - Docs - Networking - Proxy Management
I would just recommend using docker-compose to start up your stack, with the restart: unless-stopped option.
Run two containers, one for caddy and one for php-fpm, and then use php_fastcgi php-fpm:9000. Make sure that Caddy has a volume with the files for your site as well so it can see which files the app has to serve and so it can serve static files.
That could be an option! But I’m used to Dokku which is similar to Heroku deployments (buildpacks).
My question really is: is the on startup php-fpm option removed in V2, which means I have to write a docker-entrypoint.sh script instead? The migration docs did not mention this. It’s this feature: https://caddyserver.com/v1/docs/on