How to dockerize NodeJS and MongoDB application using docker-compose

In this video we will learn how to use #docker-compose to containerize a #Nodejs #express with #MongoDB as a database.

Introduction 0:00
Description of Example Repo: 0:31
Dockerizing basics: 5:46
Files needed for docker compose: 7:07
Dockerfile for Nodejs application: 9:42
Bonus (npm ci) continuous integration: 12:42
.dockerignore file: 14:16
docker-compose: 16:48
MongoDB container (service): 18:12
Nodejs container (service): 21:57
Volume for MongoDB: 27:31
Starting container (docker compose up): 28:34
Port mapping for Mongodb: 34:24
Developing using #Nodemon: 36:46
Bonus (#Redis container): 41:25

Github link of repo used:
Install Docker:
Docker Playlist:
📦FREE $100 credit @Digital Ocean:
💵Support the channel:
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I’ve been using Kite for 6 months and I love it!

✔ Other useful Playlists
#RestAPI (#NodeJS and MongoDB):
#API Authentication using #JWT:

#yoursTRULY #tutorial #howto #nodejs #android


21 thoughts on “How to dockerize NodeJS and MongoDB application using docker-compose”
  1. Hii
    I am building a microservice in docker-compose and i want that if any service crashes then it should restart automatically. i used restart tag in compose file but it is not restarting if the service crashes. All of my services in node app. Can you please help me.

  2. I followed the tutorial, however when I do "docker compose up", it gives me an error "MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". It's like the environment varaiables I declared aren't being read properly. I'm using an .env file and it works fine when I run the app outside of a container. I searched online and found no solution. Any tips? Great video btw, helped me a lot, thanks!

  3. Thank you for your tutorial. I following yours, but I’m stuck with 404 status when I access localhost:4000. While status in terminal: nodejs-rest-api-api-1 | Mongodb connected….

    What should I do to find where error(s) came from? TIA.

  4. This was very thorough. After reading many tutorials about setting up Mongo for docker, this is the only one that actually worked. I'm now looking for more details on initializing Mongo database and roles, but this video has proven very useful.

  5. How to backup MongoDb database?
    For time being i want to backup my MongoDb data to my local pc from my Vps server which is digital Ocean droplet.
    After some time I'll create new droplet and restore the database.

    If it's the mysql then i can download .sql file from exporting Through phpmyadmin. Whenever i want i can import .sql file again

    Same thing how to do with docker? For MongoDb

  6. after docker compose up… my node server is working but there is problem in database connection

  7. Can we add Mongodb Atlas URI in place of local MONGODB_URI in api service inside docker-compose but in that case I think we don't need mongodb service because now our database hosted on cloud. Am I right?

Leave a Reply

Your email address will not be published.

Captcha loading...