Logo

dev-resources.site

for different kinds of informations.

Docker in development: Episode 4

Published at
1/9/2025
Categories
docker
webdev
agile
rails
Author
sinaptia_dev
Categories
4 categories in total
docker
open
webdev
open
agile
open
rails
open
Author
12 person written this
sinaptia_dev
open
Docker in development: Episode 4

The last episode was about how to perform everyday tasks in our containers. In this episode, we will see alternatives so we can optimize our images.

.dockerignore
The first tip to decrease the size of your image was already mentioned in the second episode of this series. Having a .dockerignore file will help you control what files you don’t want in your image, and therefore it will help you decrease the size of it.

Using smaller base images
This is obvious: using smaller base images produces smaller images. In the example we’ve been constructing, we use ruby:2.6, which is based on Debian stretch. The size of this image is 870MB, and depending on your app’s dependencies they can grow easily and double it. Fortunately, there are other lightweight alternatives such as ruby:2.6-alpine3.9, based on Alpine. The size of this image is only 50.9MB. Amazing!

Dive!
There’s an excellent tool called Dive that lets you inspect your image, and therefore a way to shrink it!

FROM:latest
FROM:latest is a linter/optimizer for your dockerfiles. Try it!

Minimize layers as much as you can
Instead of doing:

RUN apt-get update -qq
RUN apt-get install -y build-essential
RUN apt-get install -y curl
Do:

RUN apt-get update -qq && apt-get install -y build-essential curl
Each line in your dockerfile produces 1 layer. Each layer increases the image size a little. Try to combine layers as much as you can (without compromising readability) like in the example above.

Tips around package managers
If you’re using apt-get (instead of Alpine’s apk), you can add --no-install-recommends to your apt-get install command. The idea is that it will install necessary dependencies only (no recommended packages). You can also add rm -rf /var/lib/apt/lists/* after installing your apt-get dependencies. It’s even better if you do it in the same layer.

If you’re using apk, you should use --no-cache, to avoid storing the cache in your resulting image.

Try to keep up
In awesome-docker, you will find new tools, tips, and tricks.

Conclusion
You should try to shrink your image as much as you can. It will help you when you’re trying to deploy your dockerized app to production.

docker Article's
30 articles in total
Favicon
Building bun-tastic: A Fast, High-Performance Static Site Server (OSS)
Favicon
Day 04: Docker Compose: Managing multi-container applications
Favicon
Infraestrutura para análise de dados com Jupyter, Cassandra, Pyspark e Docker
Favicon
Building RelaxTube: A Scalable Video Transcoding and Streaming Application
Favicon
Docker vs kubernetes
Favicon
Advanced Docker Concepts and Features
Favicon
Building and Deploying Your First Java App with Docker in Just 5 Minutes
Favicon
Realtime troubleshooting based questions docker compose
Favicon
common Docker Compose interview questions.
Favicon
[Boost]
Favicon
Docker scenario
Favicon
TOP 10 TYPES OF DOCKER COMMANDS
Favicon
how to inspect a docker container
Favicon
How to run a Nginx-web server
Favicon
Docker article Best
Favicon
Load Balancing Node.js Applications with Nginx Upstream Configuration
Favicon
Top 20 Docker Commands with Examples and Outputs
Favicon
🌟 Deploying a Live Project Without a Dockerfile Using Buildpacks 🌟
Favicon
A Conversation with Docker CTO Justin Cormack and Flux CEO Ron Efrani: The Future of Developer Environments
Favicon
Understanding Node.js Alpine Versions: A Lightweight Choice for Your Projects
Favicon
Day 03: Docker Images and Containers: Building, Pulling, and Running Docker Containers
Favicon
How would you optimize the performance of Docker containers, particularly in resource-constrained environments ?
Favicon
Docker in development: Episode 4
Favicon
Building a Local S3 Environment with MinIO: AWS SDK for Java V2 Migration Guide
Favicon
Node.js Meets PostgreSQL and MongoDB in Docker: Docker Diaries
Favicon
How to Use Docker in Your Data Science Projects: A Complete Guide
Favicon
Bringing Together Containers & SQL
Favicon
🚀 Are Your Docker Containers Secure? 🛡️ In this article, learn 10 actionable strategies to protect your Docker containers like a pro
Favicon
Running PostgreSQL, MongoDB, and NestJS concurrently with Docker Compose
Favicon
Creando un notebook con Jupyter y Kotlin

Featured ones: