Image: Exploring Docker's Building Blocks - Docker objects
Docker image - commands and use cases
Docker object: We can create, distribute, and run applications in containers with docker. The requirements and configurations required to operate these applications are built within a docker image and run in containers, which are paths of the docker objects. Docker objects are the various components and entities used within the docker environment. Such as creating and utilising images, containers, networks, volumes, plugins, and other items. Some of the benefits of docker include;
Consistency
Portability
Resource Efficiency
Versioning and Rollbacks
Rapid Deployment
In this opening post, we will explore some of the most often-used commands related to docker images. How these commands enable us to efficiently manage, manipulate, and interact with docker images, forming the bedrock of containerization technology.
Docker image
Provides the blueprint for running containers, and instances of images that are executed in isolated environments.
A standalone package that encapsulates a piece of software, including code, runtime, system tools, libraries, and settings. Once created, it remains unchangeable. Modifications result in new image layers.
Composed of multiple read-only layers that build upon each other build instructions.
Can be created based on another image with custom instructions and configuration parameters required.
Can be moved and deployed across various environments consistently, tagged with versions, making it easy to track and manage changes.
Commonly used commands and their use case includes.
Docker build:
Build a docker image from a dockerfile named "my_image" with tag "latest" in the current working directory
docker image build -t my_image:latest .
Docker pull:
Download (pull) the latest version of the nginx image from the docker public Hub
docker pull nginx:latest
Download (pull) the latest version of the nginx image from a hosted registry
docker login registry.mydomain.com
docker pull nginx:latest
Docker push:
Upload or pushes the "my_image" image to a docker registry
docker push my_image:latest
Docker image:
List pulled docker image in the local system with either command
docker images
docker image ls
Docker image remove:
Remove docker image
docker image rm my_image:latest
Docker image prune
Remove dangling image. A dangling image means images that are not tagged and are not referenced by any container
docker image prune
Remove all images which are not used by existing containers
docker image prune -a
Docker image inspect:
Display detailed information on one or more images, e.g my_image:latest
docker image inspect my_image:latest
Docker image history:
Show the history of the "my_image:latest" image layers
docker image history my_image:latest
Docker image tag:
Create a new version tag from an existing image
docker image tag my_image:latest my_image:v2
Docker image save:
Save the image to a tarball archive
docker image save -o my_image.tar my_image:latest
This method can also be used to copy images from one host to another
After saving the image, copy it with
cp
,scp
,rsync
or any preferred option to the remote host.From the remote host
docker load -i path_to_transferred_tar_file
Docker images are at the core of Docker's containerization technology, serving as the building blocks that enable the isolation and efficient deployment of applications.
In the next path, we'll expand our focus on the creation, lifecycle management, and interaction of another fundamental Docker object: the container. Containers provide a flexible and dynamic environment that encapsulates applications, their dependencies, and runtime configurations.