Image
An image contains the application binaries, application dependencies, metadata about the image and how to run the image.
Images on Docker Hub
Official images on Docker Hub just have an <image-name>
unlike others which follow the format <author-name>/<image-name>
.
Pull an image:
# Pulls the latest version
docker pull <image-name>
Pull a specific version of the image:
docker pull <image-name>:<image-version>
Pull a specific version and distribution of the image:
docker pull <image-name>:<image-version>-<dist>
Push image changes
To upload changed layers to an image registry:
docker image push <image-name>
NOTE: To perform push, we need to login with docker login
.
List all images:
docker image ls
Image layer
Image layers present a series of file system changes as an actual file system.
View image history
docker history <image-name>:image-version>
Each layer in the image has a unique SHA, so that, if another image has a same version of a layer and the layer exists in the cache, that layer will be re-used, i.e., the rest of the layers in the image are run on top of the cached layer.
Same layers are not stored more than once on the host system.
Container layer
Container layer is a read and write layer created on top of the image layer.
When a file on the image is changed as part of the container, the difference in the file is copied over to the container (copy on write) without making any changes in the history of the container.
Inspect image
# Get JSON metadata about the image
docker inspect <image-name>:<image-version>
Image tags
Tagging an image
docker image tag <source-image>:<source-tag> <target-image>:<target-tag>
Tags will default to latest
unless specified.
latest
is just a default tag that should be assigned to the newest stable version.
Build an image
docker image build -t <image-name> .
The .
will search for the default Dockerfile.
-t
is a shorthand fortag
.
Prune commands
Clean up all dangling images:
docker image prune
Clean up everything:
docker system prune
Remove all unused images:
docker image prune -a
View space usage:
docker system df
Top comments (0)