A Dockerfile is a script-like specification for constructing a Docker image. Its instructions define the microservice, dependencies, application code, and supporting assets included in the image. section 3.8.1 section 3.12
Build a Node.js microservice image incrementally:
- Select a base image with FROM, such as node:18.17.1. section 3.8.1
- Set the working directory with WORKDIR and copy package manifests into it. section 3.8.1
- Install production dependencies with RUN npm ci --omit=dev. section 3.8.1
- Copy source code and non-code assets, such as videos, into the image. section 3.8.1
- Define the startup command with CMD npm start. section 3.8.1
Build and inspect an image
From the project directory, run docker build -t video-streaming --file Dockerfile . The final period supplies the current directory as the build context. Docker produces a tagged image, which can be checked with docker image list before running it as a container. section 3.8.2 section 3.10
Listing 3.1 A Dockerfile for our video-streaming microservice
FROM node:18.17.1 #1 WORKDIR /usr/src/app #2 COPY package*.json ./ #3 RUN npm ci --omit=dev #4 COPY ./src ./src #5 COPY ./videos ./videos #6 CMD npm start #7
Use the complete Dockerfile listing to inspect how base-image selection, dependency installation, file copying, and startup instructions combine into a runnable image. section 3.8.1

















