1. Always use specific version
❌ Don't do this
FROM node
✅ Do this because it will ensure your container image version
FROM node:20.0.0
2. Try to use alpine version
❌ Don't do this because It can be use large
FROM node:20.0.0
✅ Do this for small official image
FROM node:20.0.0-alpine
3. Dont install all dependencies
❌ Don't do this
RUN npm install
✅ Do this because you don't need dev dependencies in your production server
RUN npm install --production
4. Mantain versioning
❌ Don't do this
docker build -t myapp .
✅ Do this it will help you to track version of your container images.
docker build -t myapp:1.0 .
Top comments (4)
Good list! I've always used this one as reference when I started to learn Docker: snyk.io/blog/10-best-practices-to-...
Thanks for the article.
It's a nice list which could be improved by saying why these things are bad.
Without this context, some people may think you copied AI/IDE suggestions without understanding why they are an improvement.
Thanks for the feedback updated
Very nice !