Image: Exploring Docker's Building Blocks - Docker objects

Docker image - commands and use cases

·

3 min read

Image: Exploring Docker's Building Blocks -
Docker objects

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.

  1. Docker build:

    1. 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 .
  2. Docker pull:

    1. Download (pull) the latest version of the nginx image from the docker public Hub

      • docker pull nginx:latest
    2. Download (pull) the latest version of the nginx image from a hosted registry

      • docker login registry.mydomain.com

      • docker pull nginx:latest

  3. Docker push:

    1. Upload or pushes the "my_image" image to a docker registry

      • docker push my_image:latest
  4. Docker image:

    1. List pulled docker image in the local system with either command

      • docker images

      • docker image ls

  5. Docker image remove:

    1. Remove docker image

      • docker image rm my_image:latest
  6. Docker image prune

    1. Remove dangling image. A dangling image means images that are not tagged and are not referenced by any container

      • docker image prune
    2. Remove all images which are not used by existing containers

      • docker image prune -a
  7. Docker image inspect:

    1. Display detailed information on one or more images, e.g my_image:latest

      • docker image inspect my_image:latest
  8. Docker image history:

    1. Show the history of the "my_image:latest" image layers

      • docker image history my_image:latest
  9. Docker image tag:

    1. Create a new version tag from an existing image

      • docker image tag my_image:latest my_image:v2
  10. Docker image save:

    1. Save the image to a tarball archive

      • docker image save -o my_image.tar my_image:latest
    2. This method can also be used to copy images from one host to another

      1. After saving the image, copy it with cp, scp, rsync or any preferred option to the remote host.

      2. 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.