Dockerfile Instructions
July 11, 2025
A Dockerfile is a set of instructions to build one image. Each keyword:
| Keyword | What it does |
|---|---|
FROM | Base image to start from |
WORKDIR | Working directory inside the container |
COPY | Copy files from the host into the image |
RUN | Run a command at build time (e.g. npm install) |
ENV | Set an environment variable inside the image |
EXPOSE | Document the port the app listens on (does not publish it) |
CMD | Default command run when the container starts |
Example: Node.js backend
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5000
CMD ["npm", "start"]
Example: static site via nginx
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
Remember: RUN executes while building the image; CMD executes when the
container starts. See also [[docker-basics]] and [[docker-cli-commands]].