liveBook · Manning

Dockerfile

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A Dockerfile is a script containing instructions for building a Docker image and specifying its included code and assets.

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

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains the instruction sequence and validates image creation with docker build, but does not develop advanced production Dockerfile practices.
Examples
Uses a Node.js video-streaming microservice containing source files, npm dependencies, and a sample video.
What it assumes
Assumes Docker installation and a Node.js project, while teaching Dockerfile structure from a small working example.
What you can do after
Builds and inspects a tagged Docker image from a project directory using docker build and docker image list.
How it connects
Connects Dockerfiles with Docker images, containers, container registries, microservices, Node.js, npm, and Kubernetes deployment.

Also explained in

Compare how 18 books explain Dockerfile →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.