With Docker deployment, smaller images are usually better.
But your docker images will keep changing. And you just don’t remember to check it for a while. Then someday you happen to find out some huge images in your deployment pipeline. Feel uncomfortable, don’t you? Any thoughts about how to improve it?
My answer is like always: Monitor That! And Get Slack notifications.
Enclosed is my approach. Check it out! And discuss with me, my friends.
Check More Discussion In Discussion1, Discussion2
Checking docker image size is super easy.
docker images | grep $image_name
We all want small images.
- The question is how small is small enough? It actually depends on your expectation, your project, etc.
- And you don’t set one expectation for all images, do you? More likely it would be some images should be less than 50MB, while some other should be less than 300MB, etc.
Examine it manually? It works.
But you can do better. I trust you! Maybe you can automate the check. What’s better, make the solution general. The same approach should apply to different projects with no extra effort.
Here comes my suggestion: detectbigdockerimage.py.
GitHub
- By default, the script examines all docker images in the docker host machine.
- Different images can have different check threshold.
- We can skip check for certain docker images.
Why Python instead of Shell? (See GoodBye Shell, Hello Python!)
I love Jenkins. (See 5 Reasons Why Jenkins Is So Useful And Popular).
Thus I usually create a Jenkins job, which runs the check weekly.
If the job fails, I will get slack notifications.
More Reading:
- 5 Tips For Building Docker Image
- docker-bench-security: Audit Well-Known Docker Vulnerabilities
- Run GUI Test With Docker: Detect Web Page Loading Issues
- Docker Low Disk Space. Clean Up Disk Leak!
[1] https://fralef.me/docker-and-iptables.html
[2] https://uptimerobot.com
[3] https://github.com/docker/compose/issues/3140
Blog URL: https://www.dennyzhang.com/monitor_image_size