Dockerfile
Docker allows developers to package their applications along with all dependencies into a single unit called a container. This ensures consistency across different environments, such as development, testing, and production, reducing the "it works on my machine" problem.
Install Docker: https://docs.docker.com/engine/install/
Dockerfile for the service
Add Dockerfile:
# Use the official Node.js image with specified version
FROM node:20.11-alpine3.18
# Set the working directory inside the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Install project dependencies
RUN npm install
# Copy the application code to the working directory
COPY app.js .
# Command to run the application
CMD ["node", "app.js"]
Alpine Linux is a lightweight and secure Linux distribution that is particularly well-suited for containerized environments, embedded systems, and resource-constrained environments where efficiency and security are paramount.
With this Dockerfile, we‘re ready to run it with the front-end app in the Docker Compose.