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.
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.
- 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.
- 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!
Original URL: https://dennyzhang.com/monitor_image_size