I am new to kubernetes and Dockers and microservices. I created several nodejs microservices, and use skaffold to build, run and update my deployments. Everything is working so far. However, when I run docker images
, I realised that I have many instances of the same image. Why is that so?
- Will this take up more space in my disk drive?
- am I doing something wrong?
I just realised that whenenver I make changes to my NextJS client application, skaffold will create new images. Why is that so?
2
Answers
Images are unique
This is reflected by the
Image ID
Images uses
Tags
, an image will be the same if they have same Image ID, they can have different TagsNo more space will be used for images with different tags and same Image ID
You can clean them up if you’re not using them with
docker image prune
commandI can’t say if it’s wrong, but definitely it depends on what you want to achieve
Skaffold is just creating a new image with the newest changes and building an updated image, so if this is what you want then it’s correct – just need to make sure and create a task to clean-up things that you’re not using to save disk space
I hope this answers your question
The
docker images
output and their disk space usage may be a little bit misleading for you. Bear in mind that eachImage ID
is unique, but anImage ID
can have several tags. So the actual amount of disk space used is only related to the number of uniqueImage ID
s you see. The best way to see how much disk space is being used is by issuingdocker system df
, which will show you the disk space used by images and containers.Not necessarily. It is natural to have several images if you are building repeatedly. Bear in mind that a new image is generated every time you make a change to your
Dockerfile
, because it needs to create new layers for the changed line, and every line after it (so if you change theDockerfile
frequently, one strategy is to arrange yourRUN
,COPY
, etc. commands so that you minimize the number of newly-created layers). Once you’re done building and you wish to discard the old versions, you can issuedocker image prune
(which deletes dangling images) ordocker system prune
(which gets rid of any unused build cache objects).