You need to containerize a simple Node.js microservice. The application code is available in a GitHub repository. Your task is to clone this repository and create a Dockerfile
that efficiently builds a production-ready image for the application.
https://github.com/tdevsin/nodejs-app.git
.README.md
file in the repository to understand the application structure.Dockerfile
in the root of the cloned repository to containerize the Node.js application.Dockerfile
should use an official Node.js base image.package.json
and package-lock.json
first to leverage Docker's build cache.Acceptance Criteria:
nodejs-docker-app
is successfully built.node:18-alpine
).WORKDIR
to set the working directory inside the container.package.json
and package-lock.json
before running npm install
.COPY . .
to copy the remaining application code.EXPOSE
to document the port.CMD
to define the default command to run the application.Containerizing applications with Docker is a fundamental skill in modern software development and DevOps. A well-crafted Dockerfile
ensures that your application runs consistently across different environments, from development to production. Understanding how to optimize Dockerfiles for build caching and minimal image size is crucial for efficient CI/CD pipelines and faster deployments, directly impacting development velocity and operational costs. This exercise lays the groundwork for deploying applications to Kubernetes, where container images are the primary deployment unit.