How to Containerize a MERN Application with Docker-Compose


2 min read


It is cool building a web application in your local environment, a computer until it is time to share your work with others and it doesn't run elsewhere apart from your computer. At times, it could even be versioning errors with the dependencies.

This is where containers come in.

Docker is an open-source tool that helps developers easily build, and deploy their applications as containers.

Containers contain everything an application needs to run including the source code, and dependencies.

-- Benefits of containers

In this tutorial, you will setup a development environment for a full-stack MERN app using Docker. You will create multi containers with Docker-compose.

At the end of this tutorial, you will have a working application running on Docker containers.


To complete this tutorial, you will need:

  • A computer (obviouly ๐Ÿ˜€)
  • Docker installed on your local coputer
  • A code editor like VScode

Step 1 - Clone the project

Clone the project repository and set it up on your local computer.

git clone ...

Navigate to the project directory

cd ...

Step 2 - Install Depenencies

Navigate to the backend folder and install the project dependencies.

cd backend
npm install

Navigate to the frontend folder and install the project dependencies

cd backend
npm install

Step 3 - Write the Dockerfile for each directory

Step 4 - Connect the services with Docker-compose

Step 5 - Test the application