Reputation: 1765
I created an image in docker. Installed Ubuntu, JDK in it and couple of other libraries. Then I exited the container and did a commit like this
docker commit a7b95082f6ea anil-ubuntu
I started the container again
docker run -p 5901:5901 -t -i anil-ubuntu
This time I installed gradle and couple of other libraries. And then exited the container and did a commit again.
docker commit a7b95082f6ea anil-ubuntu
Every time I do a commit a new image is created and older images with repository and tag remain. Very soon by following this workflow, I'll run out of space. Is this the right way of using docker ? How do I ensure that all these images go away.
I am using docker version 18.09.1 desktop on windows 10
Upvotes: 3
Views: 12986
Reputation: 158847
Docker images are immutable; once you create an image you can never change it again.
The correct way to create an image is using docker build
. Docker has a pretty good official tutorial on creating and running custom images; while it's Python-oriented, the basic techniques here are applicable to any language.
Using docker commit
is pretty much always wrong. A Dockerfile is just a basic listing of the steps you used to build up the image – start FROM
some base image, COPY
in some files, RUN
some commands – and it's usually just as easy to write a Dockerfile as to write out the steps involved in building up an image in text. You'll also need to work with other people on working on your image who will need this description, and for that matter when the base image you started from has a critical security fix in six months, you'll need to remember for yourself how you built it.
The workflow I generally find works is:
docker run
s locally and hand-test it. Add the Dockerfile to my source control repository.docker push
ed.Yes, this causes old images to back up, but this isn't really harmful. You can use docker system prune
to clean them up.
Upvotes: 8