DEV Community

Dockerfile Best Practices: How to Create Efficient Containers

Suleiman Dibirov on October 05, 2024

Introduction In the era of microservices and cloud computing, Docker has become an indispensable tool for application development and de...
Collapse
 
bence42 profile image
Bence Szabo

It'd be worth noting that a cleanup command e.g the one in the
Delete Unnecessary Files
section only reduce final image size when it's in the same RUN command as the install. That's one of the common pitfalls.

Collapse
 
idsulik profile image
Suleiman Dibirov

Thank you, you're right, updated the article to highlight it

Collapse
 
bobbyiliev profile image
Bobby Iliev

Great post! Well done!

For anyone interested in learning more about Docker in general, I could suggest this free eBook here:

GitHub logo bobbyiliev / introduction-to-docker-ebook

Free Introduction to Docker eBook

💡 Introduction to Docker

This is an open-source introduction to Docker guide that will help you learn the basics of Docker and how to start using containers for your SysOps, DevOps, and Dev projects. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you will most likely have to use Docker at some point in your career.

The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Docker.

🚀 Download

To download a copy of the ebook use one of the following links:

📘 Chapters

Collapse
 
chibx profile image
Chiebidolu Chinaemerem

Great suggestion.
Haven't read through it thoroughly, but I love the layout, and the table of content is a beauty

Collapse
 
amrikasir profile image
Al Amrikasir

The timing is insane, I read this article when I need to optimize docker image.

Thanks a lot man, you just save me 🙏

Collapse
 
denys_bochko profile image
Denys Bochko

very nice, thanks. there are a couple of things I did not know about, will be restructuring my dockerfiles

Collapse
 
regisnew profile image
Rodrigo Régis Palmeira

Congratulations. Very good examples. Thanks for sharing.

Collapse
 
lovelindhoni profile image
Lovelin

A great post fr. Thanks man, much needed

Collapse
 
indomie profile image
Kentang Balado

Nice post!.
Thanks for sharing.

Collapse
 
click2install profile image
click2install

Use a linter like hadolint, simple.

Collapse
 
robertomaurizzi profile image
Roberto Maurizzi • Edited

Write about caching intermediate files to speed up builds and saving on download time/bytes (nothing better than having to work on a 50kB/s connection in a developing country to learn that...)

Collapse
 
redev1l profile image
Kirill Naumenko

You dont do npm ci in dockerfile, because you cant get env vars dynamically from ur CI engine, without scripting.
You build your app in CI environment and then copy artifacts to dockerfile.