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.
Wish I had found this post before I started playing with Docker, as it is packed with solid advice which I found out “along the way” myself.
In short:
- Find the right balance with the cache layers
- Use
.dockerignore
files - Use the multi-stage builds feature
- Choose the right base image
Especially number 3 was an eye opener to me when I first discovered it. Basically it boils down to this: Don’t do an npm install
/composer install
/npm build
directly in your “main” image, but do it in a separate container and afterwards copy its results into your main image.
Leave a comment