I have a Node.js app together with a MongoDB database running on AWS ECS. The setup I've got currently is formed of 2 ELB's and 2 Instances running each a Docker container with its assigned service (node/mongo):

Elastic Load Balancer -> Dockerized Node -> Elastic Load Balancer -> Dockerized MongoDB

I am running the Official Docker image for MongoDB available here: https://registry.hub.docker.com/_/mongo/

Any pointers as to how would I be able to deploy a replicaSet for MongoDB using Docker and ECS, each replica running on a different instance?

2 Answers 2


Don't dockerize databases. Docker containers are meant to be ephemeral and not hold data. That's not appropriate for databases.

In particular, do not attempt to dockerize a MongoDB cluster. The setup for replica sets is extremely stateful and complex. You have to run many commands in order and only once. If you miss any command or if a node goes off, the entire cluster might dead lock and you'll be forced to start over.

Docker has its own idea of how applications should behave. It would be really difficult to make that work inside Docker.

If you want a cluster with 3 replicas, you should get 3 AWS instances and setup MongoDB on the instances. Search for mongodb setting up a replica set on <OS> on Google, that will give you an up to date tutorial.


FireCamp does it. FireCamp could deploy a MongoDB ReplicaSet on AWS ECS very easily. 1) deploy the ECS cluster with cloudformation template, 2) deploy the MongoDB ReplicaSet by a single command. Check FireCamp Installation wiki for the details.

For security, it is better to run the Node.js app in another ECS cluster. The EC2 instances that run MongoDB should not be exposed to the external world.

The Elastic Load Balancer is not required for the Node.js app to access MongoDB ReplicaSet. Every replica gets a unique dns name. Node.js app could simply access MongoDB by the dns name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .