• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Abhishek Tanwar

I build web & mobile experiences

  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS
You are here: Home / Fullstack / How To Setup MERN Stack On Docker?

How To Setup MERN Stack On Docker?

June 20, 2018 by Abhishek Tanwar

Recently I have been exploring docker and docker-compose and I majorly work on MERN stack for my web apps hence this blog.

This blog will give you steps how you can setup a fully connected MERN application with ReactJS front end, Express JS as backend, Mongo as database and Node as server.

Lets get started.

Pre Requisites

  1. You already have installed docker, docker-compose
  2. You have an editor of your choice. I recommend VSCode.

App Structure

React App

I created a simple ReactApp using Official Start Page as reference. Its pretty simple. Once you have a simple react App running, all we need to do is add a “Dockerfile” and standard “.dockerignore” file as below:

react-app-docker
react-app-docker
dockerignore
dockerignore

Express App

Again, I created a simple express app. You can refer this link for the express app. I used standard express app and a simple database connection. For now the app don’t do anything. You can ignore the docker-compose from the link for now for the express app.

Now your both react and express app are ready with docker files.

Docker Compose

Lets create our connected e2e service layer now. This is done via docker-compose configuration. Create a file outside the two folders and have below information in it. I will explain the details.

docker-compose.yml
docker-compose.yml

Now lets see what the yml file is about:

  1. defines a version of docker-compose utility.
  2. defines the services to be used.
  3. react-app
    • service to handle our react app
    • specify container name
    • specify image name
    • build path for the app where the docker file is present
    • command to run the service
    • any environment variables to pass
    • maps 5000 container port to 5000 outside port hence our react app will be running on port 5000.
  4. express-app
    • service to handle our express app
    • specify container name
    • specify image name
    • build path for the app where the docker file is present
    • command to run the service
    • maps 5000 container port to 5000 outside port hence our react app will be running on port 5000.
    • depends on mongo to specify the starting order and have express connect to mongo via service name
  5. mongo
    • mongo database
    • specify container name
    • image to be used
    • maps 27017 container port to 27017 outside port
  6. adminmongo
    • viewer for mongo database
    • specifies the image name
    • specify container name
    • maps 1234 container port to 1234 outside port

My folder structure looks like below:

folderstructure
folderstructure

Build

docker-compose build

Run

docker-compose up -d

If all goes ok, you should be seeing below output which indicates our applications are deployed and hosted on docker now.

docker-compose-up
docker-compose-up

Note: it may be required to restart express-app so that it can reconnect to mongo service.

That’s it! You have successfully setup the MERN stack on docker. Happy coding!

Share this:

  • Facebook
  • X

Like this:

Like Loading...

Filed Under: Fullstack, Tips & Tricks Tagged With: express application on docker, mean stack on docker, mern on docker, react on docker

Primary Sidebar

  • Behance
  • Email
  • Facebook
  • GitHub
  • LinkedIn

Popular Posts

How To Integrate React in JSP Application
SaaS, PaaS, IaaS
XQuery highlighting in Notepad++
Standard Design Patterns – Applied to JAVA
XQDT Installation on Eclipse JUNO

Categories

  • Building APIs
  • Building Mobile Apps
  • Building Web Apps
  • Coding Challenges
  • Extensions
  • Fullstack
  • Patterns
  • Tips & Tricks
  • Uncategorized
  • VSCode

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Recent Posts

  • 15+ VSCode Extensions To Improve Your Productivity
  • Productivity and Quality Extensions for ReactJS in VSCode..
  • My goto VSCode plugins for 2022…
  • How to enable MFA for your application in Node.JS?
  • Structuring Express Application – How I do it?

Categories

  • Building APIs (8)
  • Building Mobile Apps (1)
  • Building Web Apps (7)
  • Coding Challenges (3)
  • Extensions (1)
  • Fullstack (6)
  • Patterns (8)
  • Tips & Tricks (41)
  • Uncategorized (43)
  • VSCode (2)

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Archives

  • August 2023 (1)
  • March 2022 (1)
  • February 2022 (1)
  • November 2020 (1)
  • April 2020 (2)
  • May 2019 (1)
  • April 2019 (1)
  • March 2019 (1)
  • December 2018 (1)
  • July 2018 (4)
  • June 2018 (3)
  • March 2018 (1)
  • May 2016 (1)
  • December 2015 (1)
  • May 2015 (1)
  • April 2015 (2)
  • March 2015 (1)
  • December 2014 (2)
  • November 2014 (2)
  • October 2014 (1)
  • August 2014 (2)
  • July 2014 (1)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (2)
  • January 2014 (1)
  • December 2013 (4)
  • November 2013 (4)
  • October 2013 (3)
  • September 2013 (4)
  • August 2013 (2)
  • July 2013 (5)
  • June 2013 (9)
  • May 2013 (6)
  • April 2013 (2)
  • March 2013 (2)
  • January 2013 (1)
  • November 2012 (2)
  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS

Copyright © 2025

%d