Docker Caddy and PHP app in seperate containers

Hello,

this is more of a general question on how others use their PHP-FPM docker containers in production in conjunction with Caddy.

The main question is how do you share static files between seperate Caddy and PHP containers if you prebuild the php-fpm container bundled with the code in CI/CD?

What most “solutions” to the problem are, is to put the code onto the server and mount it into both the Caddy container and the PHP container.

Others suggest to put Caddy into the PHP-FPM container with the code and serve it in a bundle. (I’m currently doing this). Having a PHP-FPM container with caddy in it feels kind of bad to me because I don’t want to manage caddy in my own container.

Using Caddy with the reverse_proxy directive to send the requests to a normal Apache/PHP container was very slow in my tests.

I would appreciate learnings or best practices from others how you handle PHP apps in production environments.

Best regards, Markus

This is what most people do.

If you have a build process and you ship images to production, then you could copy the source code into both a Caddy image and a PHP-FPM image. Basically the files just need to be “the same”. If your files can change though (like uploads or something) then you’d have to mount that as a volume to persist the changes etc.

You can do this too, there’s a neat plugin for Caddy GitHub - Baldinof/caddy-supervisor: Run and supervise background processes from Caddy which can have Caddy actually run the php-fpm service itself. But this is less common and has a bit more setup cause you need to craft the Dockerfile yourself to have both caddy and php-fpm installed in the same image (no official ones shipped this way).

2 Likes