Search code examples
docker

Can I run multiple programs in a Docker container?


I'm trying to wrap my head around Docker from the point of deploying an application which is intended to run on the users on desktop. My application is simply a flask web application and mongo database. Normally I would install both in a VM and, forward a host port to the guest web app. I'd like to give Docker a try but I'm not sure how I'm meant to use more than one program. The documentations says there can only be only ENTRYPOINT so how can I have Mongo and my flask application. Or do they need to be in separate containers, in which case how do they talk to each other and how does this make distributing the app easy?


Solution

  • There can be only one ENTRYPOINT, but that target is usually a script that launches as many programs that are needed. You can additionally use for example Supervisord or similar to take care of launching multiple services inside single container. This is an example of a docker container running mysql, apache and wordpress within a single container.

    Say, You have one database that is used by a single web application. Then it is probably easier to run both in a single container.

    If You have a shared database that is used by more than one application, then it would be better to run the database in its own container and the applications each in their own containers.

    There are at least two possibilities how the applications can communicate with each other when they are running in different containers:

    1. Use exposed IP ports and connect via them.
    2. Recent docker versions support linking.