Node.js & MongoDB: A Beginner's Guide to Building Modern Web Applications
Jagan Rajagopal AWS Certified Solution Associate ,Aws Coach Jagan ,Azure ,Terraform
AWS Certified Solution Architect | 6K Followers | Aws Coach Jagan Certified AWS Solutions Architect | Freelance on Cloud | DevOps Expert | Azure Solution Architect | Terraform | Gitlab | Devops | Kubernetes | IAC
Dockerfile for Node.js Application
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Docker can build images automatically by reading the instructions from a Dockerfile.
Here's a simple example of a Dockerfile for a Node.js application:
# Use an official Node runtime as a parent image
FROM node:14
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy the current directory contents into the container at /usr/src/app
COPY . .
# Install any needed packages specified in package.json
RUN npm install
# Make port 3000 available to the world outside this container
EXPOSE 3000
# Run app.js when the container launches
CMD ["node", "app.js"]
This Dockerfile does the following:
领英推荐
Docker Compose and docker-compose.yml
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.
A docker-compose.yml for a Node.js application with MongoDB might look like this:
Please check the docker-compose.yml in githubcode ->Docker-compose.yml
This docker-compose.yml file does the following:
Steps to Run Your Application
Docker Compose is particularly useful for development and testing environments, allowing you to easily link your application with services like databases without manual configuration or having to install these services on your development machine.
Nodejs Application on RestApi with Mongodb database with Handsonlab
Please check with github source code: https://github.com/jaganrajagopal/DockercomposeNodejsMongodb.git