How to start a Node.js project using Docker Compose

In this tutorial, we are going to create all the required Docker containers and we will start them in the local environment using Docker Compose.

Setup basic auth on Mockless Studio

The focus of this tutorial would be to migrate a simple Node.js REST API to a containerization Node.js app using Docker.

As the output of this tutorial would be to start the API on local environments, as an orchestration method we are using Docker Compose.

Prerequisites

This tutorial uses an already created Node.js project that was described here.
In case you are not familiar with Mockless Studio or you don’t have any Mockless projects yet, we encourage you to create your first project as we described here.

To successfully follow this tutorial you will have to have an account on Mockless Studio.

Activating Docker and Docker Compose plugins

On Mockless Studio, running a Node.js REST API using docker is as simple as enabling a plugin.

The first step is to go to the Packaging section under the Project Settings and to enable the Docker Packaging method as shown below:

Integrate Mongo Express (optional)

As the MongoDB instance will be started using Docker, we can enable the Mongo Express plugin that will run automatically on port 8080 for managing the MongoDB collections.

Creating the environment

The last step would be to create a new Development environment to be configured to run the Node.js REST API using Docker and Docker Compose.

Testing the app

As now we have everything configured, we have to build the Mockless project, pull the latest git commits and start it on the local environment.