On an old server, I have a PHP app with postfix on the same server, so when emails get sent, they simply make it to postfix, where they sit in the email queue.
I’m trying to convert the app to docker, and am having trouble with the email side. I originally had a php-3.7-fpm-alpine image, but when I installed postfix on there, I couldn’t figure out any way to get it started (there was no init.d file, doesn’t look like alpine has a service, etc). So I tried using the base php 7.3 fpm image, but when I try to install postfix there, it gets blocked because postfix has a installation guide there.
But on a docker discord, someone suggested I was looking at it wrong. They suggested in docker, there shouldn’t be two main processes in a single container. However, a friend was concerned by the idea of postfix on a separate container, because if there are any communication issues between the php container and the postfix container (packet issues, postfix down when php sends a message, etc), the email is lost forever.
If anyone has any advice on setting up this system, I’d really appreciate it.
People on discord were right, however, you could use Supervisor to have multiple processes in a container, if you really need it. But then you would have to install python packges and change the command in the container so do it if you are not able to do it otherwise.
It depeneds on where your containers are. If they are on different machines, network issues can be a problem. If both containers are on the same machine using Docker network, the chance you have communication error is much less. A firewall misconfiguration can disable network traffic between the containers, but it would be a permanent issue.
A probably better way: using the same network namespace in the containers
Containers are like people in jail who are allowed to work together. You can tell how they can communicate. You can say some people can’t communicate with anyone, or they can but only on one channel. They can’t share food (they don’t have volumes) but they can hear eachother. These channels are the network namespaces in the container world.
You can share only one namespace, like the network namespace so the two containers are on the same loopback interface (localhost imeans the same for both). In that case they can communicate as long as both of them are running.
docker run -d --name php-fpm IMAGENAME
docker run -d --name postfix --network container:php-fpm IMAGENAME