# Dockerfile Basics — Docker Fundamentals: Images, Containers and Compose

Source: https://www.skillbyai.com/en/docker/docker-dockerfile-basics

> Write a Dockerfile with FROM, WORKDIR, COPY, RUN and CMD, and know build-time versus run-time instructions.

## What is a Dockerfile?

A **Dockerfile** is a plain-text recipe of instructions that Docker follows, top to bottom, to build an image.

## A minimal Node app

`FROM` sets the base image, `COPY` brings in your files, `RUN` executes build-time commands, and `CMD` sets the default startup command.

```dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package.json .
RUN npm ci
COPY . .
CMD ["node", "server.js"]
```

## RUN vs CMD

`RUN` executes **during the build** and its result is baked into the image. `CMD` only runs **when a container starts** — one image can have many `RUN`s but usually just one `CMD`.
