liveBook · Manning

Docker build

As explained in Road to Kubernetes

docker build is a Docker command that constructs a container image from a Dockerfile and build context.

docker build constructs a container image from a Dockerfile and its build context. It turns repeatable setup steps—copying application files, installing dependencies, setting permissions, and choosing a startup command—into a portable image. section 5.4.2

Build and run a Node.js image with a tagged name:

  • Build it: docker build -t rk8s-js -f Dockerfile . section 5.4.2
  • Run it: docker run -p 3000:3000 rk8s-js. section 5.4.2
  • Override settings when running: docker run -p 3002:3000 -e MESSAGE="Hello World" rk8s-js. section 5.4.2
Listing 5.13 Node.js Dockerfile
# Using the official Node.js image for the LTS version
FROM node:18.17.0

# Set our app's working directory
WORKDIR /app

# copy the primary source code
COPY ./src /app/src/

# copy the package.json and package-lock.json to
# ensure we use the same dependencies
COPY package.json /app/
COPY package-lock.json /app/

# copy the entrypoint.sh for running the app
COPY conf/entrypoint.sh /app/

# install dependencies
RUN npm install

# make the entrypoint.sh executable
RUN chmod +x entrypoint.sh

# run our app
CMD ["./entrypoint.sh"]

Inspect the Dockerfile behind the build: it selects Node.js 18.17.0, copies source and lockfiles, installs dependencies, and defines the entrypoint. section 5.4.2

Build for different environments

Use separate Dockerfiles and tags for development, staging, and production: docker build -f Dockerfile.prod -t my-container:prod . Registry-bound images need valid tags, typically including a username, repository name, and tag. section 7.2.1 section 5.5

How Road to Kubernetes covers it

How deep it goes
Explains Dockerfile-driven builds, runtime checks, registry tagging, and environment variants without detailing Docker’s internal build engine.
Examples
Demonstrates Node.js builds, runtime port and environment overrides, Docker Hub publishing, and development, staging, and production Dockerfiles.
What you can do after
Apply it via Docker to build tagged images, run them with configuration overrides, and prepare valid registry-bound artifacts.
How it connects
Connects Dockerfiles, container images, build contexts, docker run, Docker registries, Docker Hub, and environment-specific tags.

Also explained in

Compare how 4 books explain docker build →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.