💾Thananjhayan
← Back to notes

Dockerfile Instructions

July 11, 2025

A Dockerfile is a set of instructions to build one image. Each keyword:

KeywordWhat it does
FROMBase image to start from
WORKDIRWorking directory inside the container
COPYCopy files from the host into the image
RUNRun a command at build time (e.g. npm install)
ENVSet an environment variable inside the image
EXPOSEDocument the port the app listens on (does not publish it)
CMDDefault 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]].

💬 Comments