Docker Best Practices for Production

nipu

Nipu Chakraborty

Posted on September 2, 2023

Docker Best Practices for Production

1. Always use specific version

❌ Don't do this

FROM node
Enter fullscreen mode Exit fullscreen mode

✅ Do this because it will ensure your container image version

FROM node:20.0.0
Enter fullscreen mode Exit fullscreen mode

2. Try to use alpine version

❌ Don't do this because It can be use large

FROM node:20.0.0
Enter fullscreen mode Exit fullscreen mode

✅ Do this for small official image

FROM node:20.0.0-alpine
Enter fullscreen mode Exit fullscreen mode

3. Dont install all dependencies

❌ Don't do this

RUN npm install
Enter fullscreen mode Exit fullscreen mode

✅ Do this because you don't need dev dependencies in your production server

RUN npm install --production
Enter fullscreen mode Exit fullscreen mode

4. Mantain versioning

❌ Don't do this

docker build -t myapp .
Enter fullscreen mode Exit fullscreen mode

✅ Do this it will help you to track version of your container images.

docker build -t myapp:1.0 .
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
nipu
Nipu Chakraborty

Posted on September 2, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related