Building on Michael's explanation, I’d like to suggest an alternative approach using a tool I wrote called monofy. It's a Python-based solution designed to manage multiple processes within a single Docker container, ensuring they start, run, and stop together.
How It Works
- Single Parent Process:
monofy runs as the parent, starting all your services as child processes. This allows for proper signal handling, forwarding signals like SIGTERM to all child processes for a clean shutdown.
- Unified Logging: It consolidates stdout and stderr from all child processes, simplifying monitoring.
- Connected Fate: If one process exits,
monofy terminates all other processes, ensuring they stop together.
Example Implementation
Consider you have two services, service1 and service2, tightly coupled within your application. Here’s how you could modify your Dockerfile:
FROM python:3.12
RUN pip install monofy
CMD ["monofy", "service1", "|||", "service2"]
This setup runs both service1 and service2 in a single container with proper process management, logging, and shutdown handling—without extra tools like supervisor or phusion/baseimage.