Multiple applications in a single container!

You can, but you have to build all the mechanism to keep all of the processes running yourself. Supervisord seems to be a popular solution.

I think it’s generally considered a best practice to run only one “thing” in a container. There are a couple of reasons for this. One is just that it’s simpler (two docker run commands or a docker-compose.yml file, rather than trying to manage supervisord). Another is that you’ll probably need to routinely update your application, and if the application and the database are in separate containers you don’t need to restart one part just because the other’s changed.

If you’re looking at a multi-host setup (like Docker Swarm or Kubernetes) then keeping the database and application separate becomes more important. The database needs some special care; you can’t replicate it and it’s tricky to move it across hosts. If the application is stateless (up to its database connection) you can run multiple copies of it, and you don’t especially care where they run. Those are different enough that you really want them to be separate things so that you can manage them separately.

1 Like