Docker 101: Understanding Images and Containers in Plain English

mjsf1234

mrityunjay saraf

Posted on June 23, 2023

Docker 101: Understanding Images and Containers in Plain English

πŸ“Œ Table of content

πŸ“What is Docker

πŸ“Advantage of Docker

πŸ“Architecture of Docker

πŸ“What is Image

πŸ“What is Container

πŸ“Docker Commands

πŸ“Image Commands

πŸ“Container Commands

πŸ”Ž What is Docker

docker meme

  • Docker is an open-source platform that enables the packaging, distribution, and deployment of applications using containerization.

  • Docker uses an isolated environment called container on the host OS to run applications. It allows applications to use the same Linux kernel as a system on the host computer, rather than creating a whole virtual OS.

  • Docker works only on the Linux kernel.

difference between docker and VM

✨ Advantage of Docker

πŸ‘‰Portability: Containers are highly portable, allowing applications to run consistently across different environments.

πŸ‘‰Scalability: Docker enables efficient scaling of applications by quickly creating and deploying multiple containers.

πŸ‘‰Isolation: Containers provide a level of isolation between applications, improving security and preventing conflicts between dependencies.

πŸ‘‰Efficiency: Docker's lightweight architecture and shared OS resources result in efficient resource utilization and faster application startup times.

πŸ”‘ Key concept of Docker

  • Containers,Images,Docker Registry is discussed soon in detail in different section of this blog.

  • Dockerfile: A Dockerfile is a text file that defines the instructions for building a Docker image.

Building image from dockerfile

Docker Engine: The Docker Engine is the runtime that enables the execution of Docker containers.

🧬 Architecture of Docker

  • Docker client : provide the user an interface to communicate with the docker daemon in form of commands and REST API's req.
  • Docker Host : It is the physical or virtual machine where the docker runtime environment is installed. It run the docker daemon (server) which listened to request from the docker client and manages the container and images.
  • Docker registry : A Docker registry is a central repository that stores Docker images.
    • Public Registry: Access to everybody for ex : DockerHub
    • Private Registry: registry accessed by any particular organisation.

understanding docker architechture

understanding docker architechture

πŸ“” What is an Image

  • A Docker image is a blueprint for creating containers. It contains all the necessary files, dependencies, configurations, and instructions for running a specific application or service.
  • Each container created from an image is an instance of that image
  • Docker images are stored in a registry, such as Docker Hub

understanding the image

πŸ“¦ What is the Container

πŸ‘‰A Docker container is a lightweight and isolated runtime instance created from a Docker image.
πŸ‘‰Docker containers encapsulate applications and their dependencies, providing a consistent and isolated runtime environment.
πŸ‘‰Docker containers are highly portable and can run consistently on different systems, such as development machines, servers, cloud platforms.
πŸ‘‰Docker containers can be easily scaled horizontally by running multiple instances of the same container.
πŸ‘‰ After the allocation of the host system resources to image container is created.

  • Image + Some part of your system resources (cpu,memory,storage) . = Container

  • Below example shows how container is made out of an image πŸ˜€

understanding the container

πŸ“Œ Docker Commands

πŸš€ Image Commands

  • docker image pull <image-name>:<tag>:Pull an image from a registry
mrityunjay:~$ docker image pull redis:latest
latest: Pulling from library/redis
5b5fe70539cd: Pull complete 
a1bc4b7ad0f0: Pull complete 
a33d2f01ead9: Pull complete 
94b33095e71c: Pull complete 
d3c2b649b97c: Pull complete 
8a5bf7f0acd7: Pull complete 
Digest: sha256:6ccde0cb87c24c09b1970802b10e702ab4491ac932b79f69682609787379fa42
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
Enter fullscreen mode Exit fullscreen mode
  • docker image ls: show all the images
mrityunjay:~$ docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
redis        latest    8e69fcb59ff4   7 days ago   130MB
Enter fullscreen mode Exit fullscreen mode
  • docker image inspect <image_name or image_id> :Display detailed information on one or more images
mrityunjay:~$ docker image inspect redis
[
    {
        "Id": "sha256:8e69fcb59ff4a25f87cf68cf2558df9c56df3c3c8ef709677dc602a458fe9b2d",
        "RepoTags": [
            "redis:latest"
        ],
        "RepoDigests": [
            "redis@sha256:6ccde0cb87c24c09b1970802b10e702ab4491ac932b79f69682609787379fa42"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2023-06-14T21:57:04.72797832Z",
        "Container": 
        ....


Enter fullscreen mode Exit fullscreen mode
  • docker image rm <image_id / image_name>: Delete one or more images
mrityunjay:~$ docker image rm redis
Untagged: redis:latest
Untagged: redis@sha256:6ccde0cb87c24c09b1970802b10e702ab4491ac932b79f69682609787379fa42
Deleted: sha256:8e69fcb59ff4a25f87cf68cf2558df9c56df3c3c8ef709677dc602a458fe9b2d
Deleted: sha256:fe526a32129d428c70598b5002c0c36375de4c593d5e9a9c5cb23b3029be6535
Deleted: sha256:5ae934b4bc8f1f63c0c096d7c33b9aa6782e4bf32c6584ab4a3374a5c2fea61b
Deleted: sha256:ad2888d341396ec43ce8c9526f4f706951cdd46b9c5c68248560fe19b7eeeebc
Deleted: sha256:ab6989ff03a00c9b4e5524e3858ba3ad6c939482d48434ad61c49bb5d390d31d
Deleted: sha256:67fa40895a637a6ffa36df77928cdd46f9f28f9ca2e7a5f5d1ca4851875b4956
Deleted: sha256:ac4d164fef90ff58466b67e23deb79a47b5abd30af9ebf1735b57da6e4af1323

Enter fullscreen mode Exit fullscreen mode
  • docker image push <image-name>:<tag>:Push an image or a repository to a registry
  • docker image build . : Build image from dockerfile

πŸ“ NOTE : If you need any help related to docker image command just type

docker image command --help

mrityunjay:~$ docker image command --help

Usage:  docker image COMMAND

Manage images

Commands:
  build       Build an image from a Dockerfile
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Display detailed information on one or more images
  load        Load an image from a tar archive or STDIN
  ls          List images
  prune       Remove unused images
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rm          Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Run 'docker image COMMAND --help' for more information on a command.

Enter fullscreen mode Exit fullscreen mode
  • πŸš€ Container Commands

  • 🎯 Creating the Container: This command will create the container of specific image in an interactive mode. But this will not run the container.

docker container create -it --name <container_name> <image_id / image_name>
Enter fullscreen mode Exit fullscreen mode
  • 🎯 Starting the Container: docker container start will start the container. -i will open container's console for i/o . CONTAINER is either name or id of the container.
docker container start -i CONTAINER
Enter fullscreen mode Exit fullscreen mode
  • 🎯 Running the Container : docker run command will create and run the container --name will name the container and -it allow you to interact with the container's console. -d option make container run in deatched mode.
docker run -it --name <container_name> -d <image_name>
Enter fullscreen mode Exit fullscreen mode
  • 🎯 Running the Command in Container: docker exec will execute the command in docker container. -it will enable interactive mode. container is either container name or id command specify the command to be executed.
docker exec -it CONTAINER COMMAND
Enter fullscreen mode Exit fullscreen mode
  • 🎯 Stopping the Container : docker container stop will stop the running container mycontainer is either name or id of container.
docker container stop mycontainer
Enter fullscreen mode Exit fullscreen mode
  • 🎯 Kill the Running Container : docker container kill command will forcefully terminate the container after try stopping conatiner gracefully using docker container stop command. mycontainer is either container name or container id.
docker container kill mycontainer
Enter fullscreen mode Exit fullscreen mode
  • 🎯 Removing the container : docker container rm will remove the container. mycontainer is one of more container_name or container_id.
docker container rm mycontainer
Enter fullscreen mode Exit fullscreen mode

πŸ“ NOTE : If you need help for the docker container command

docker container command --help

mrityunjay:~$ docker container command --help

Usage:  docker container COMMAND

Manage containers

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  inspect     Display detailed information on one or more containers
  kill        Kill one or more running containers
  logs        Fetch the logs of a container
  ls          List containers
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  prune       Remove all stopped containers
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  run         Run a command in a new container
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker container COMMAND --help' for more information on a command.
Enter fullscreen mode Exit fullscreen mode

🌟 This is all about Images and Containers.In next blog will be be going to see how to Container the appication.

πŸ’¬ If you enjoyed reading this blog post and found it informative, please take a moment to share your thoughts by leaving a review and liking it πŸ˜€

πŸ’– πŸ’ͺ πŸ™… 🚩
mjsf1234
mrityunjay saraf

Posted on June 23, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related