In the previous post we saw on how to pull and run Docker
Images from a remote repository. Once we pull a Docker Image, it gets stored in
the local repository. We can use the image
ls command to view the list of images in the local repository.
List all images
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 7 months ago 13.3kB
Once we list out the images in the local repository, we can remove images from
the local repository using the image rm command.
Remove Docker Image
$ docker image rm hello-world
Error response from daemon: conflict: unable to remove repository reference
"hello-world" (must force) - container 13e04182e0c8 is using its
referenced image bf
756fb1ae65
The above command threw a conflict message since there is a docker container
still referencing to the image, in this case we will first have to remove the
referencing container or user the force option. Once we remove the referencing
container the image can be removed.
$ docker image rm hello-world
Untagged: hello-world:latest
Untagged:
hello-world@sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted:
sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
Removing dangling images
Docker provides a docker image prune command that can be used to remove
dangled and unused images.
A dangling image is an image that is not tagged and is not used by any
container. To remove dangling images type:
$ docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Removing all unused images
To remove all images which are not referenced by any existing container use
the prune command with the -a option:
$ docker image prune –a
WARNING! This will remove all images without at least one container associated
to them.
Are you sure you want to continue? [y/N] y
List all Networks
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
7f2e47e74531 bridge bridge local
0e8c762a9a44 host host local
c6882d31c84a none null local
No comments:
Post a Comment