I have a simple MEAN app that I want to run multiple times, only problem is I don't want each instance of the app to point at the same database. To solve this in Docker I am placing the Node code and the MongoDB in the same container. The code references a specific DB, but it doesn't matter as each container has its own internal DB server. Obviously this is wasteful and not best practice so I am looking for an alternative solution.
Ideally I want to keep one Docker image with one instance of the Node code, I know I could just rebuild the Docker image twice, with two different environment variables, but that doesn't scale well.
I was thinking I could use Docker networking to reference a single DB server container, and then for each container containing my Node code, have the entry point as a custom script that sets an argument passed to it as an environment variable before starting the Node server. That way whenever I run a container from that image, I pass a new DB name to it as an argument that the Node code will read. This way I could create unlimited containers from one image, all with unique databases but pointing to the same DB server.
I'm unsure if this is the best way though, and if there are any best practices that surround this. Can anyone help me with this?
Thanks