DockerPlay
🎖️
3d
Chapter 0815 mins • intermediate

Writing Dockerfiles & Build Cache

FROM, WORKDIR, COPY, RUN, CMD & Cache Optimization

What You Will Master:

  • Master essential Dockerfile instructions: FROM, WORKDIR, COPY, RUN, EXPOSE, CMD
  • Understand layer caching rules and cache invalidation
  • Build custom images using `docker build -t myapp .`

1Core Dockerfile Instructions

  • FROM node:22-alpine: Sets the base image blueprint.
  • WORKDIR /app: Sets current directory for following commands.
  • COPY package*.json ./: Copies dependency manifests.
  • RUN npm install: Executes shell command during build time to create layer.
  • COPY . .: Copies application source code.
  • EXPOSE 3000: Documents intended container listening port.
  • CMD ["npm", "start"]: Default process executed when container starts.
Interactive Lab

Build a Custom Application Image

Build a custom application image tagged `myapp:1.0` from current directory context.

0/1 Steps
Step 1: Build image with tag myapp:1.0

Run `docker build -t myapp:1.0 .` in the terminal.

Chapter Knowledge Quiz

Pass the 3-question assessment to earn +50 XP and complete this chapter.

Sponsor & Resources