Main idea
A Dockerfile should not only work once. It should also be easy to understand and easy to maintain later.
This page focuses on writing Dockerfiles that are clean, stable, cache-friendly, and safer for long-term project work.
A Dockerfile should not only work once. It should also be easy to understand and easy to maintain later.
Pick base images intentionally, use stable versions, use `WORKDIR`, support caching, and keep startup commands clear.
Using `latest`, copying everything too early, or storing secrets in Dockerfiles creates future problems.
FROM node:18-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY server.js .
EXPOSE 3000
CMD ["npm", "start"]Next page: Lesson 13 compares bind mounts and volumes for development and persistent storage use cases.