How to build a smaller Docker image

When you’re building a Docker image it’s important to keep the size under control. Having small images means ensuring faster deployment and transfers.

Proper planning prevents poor performance

Find the right balance with the cache layers

Use --squash flag on build

Use .dockerignore files

Sending build context to Docker daemon 2.048kB
Step 1/9 : FROM ...
COPY . /var/www

Use the multi-stage builds feature

docker images <image> --format "{{.Repository}}:{{.Tag}} {{.Size}}"

Choose the right base image

Let’s create the smallest image possible

In conclusion

I save the time of developers like me with automation. Working @ Klarna