Have you ever noticed that you create an application that works flawlessly on your computer, but when you pass it on to someone else, it doesn't exactly work on theirs?

What is Docker?

Docker is a container platform that enables rapid development, testing, and deployment of applications. A Dockerfile defines all of the applications and their dependencies, which is then used to build Docker images that define a Docker container. This guarantees that your application will work in any environment.

How does it work?

To execute, a VM application requires a guest OS and consequently an underlying hypervisor. A hypervisor is used to generate and manage virtual computers on a host operating system. These virtual machines have their operating system and do not rely on the hosts. They have some room set aside for them. A containerization is an effective approach to delivering programs in the software industry. A container protects an application by enclosing it in its operating environment. It may be installed on any host machine without any particular configuration, eliminating the need for dependencies. Containerization is OS virtualization, whereas VM is hardware virtualization. Virtualization, on the other hand, is the construction of a virtual version of something, such as an operating system, server, storage device, or network resources. Essentially, containerization is a lightweight approach to virtualization.

Why use Docker?

  • Your applications will be delivered quickly and consistently.

  • Scalable and responsive deployment.

  • More workloads may be run on the same hardware.

What is a Container?

  • A method of packaging an application with all of its dependencies and settings.

  • A portable artifact that can be readily shared and moved about.

  • Increases the efficiency of development and deployment.

Where do you store Containers?

  1. Public Repository: Docker images may be hosted in public repositories and utilized by everyone.

  2. Private Repository: Private repositories allow you to keep container images private, either to your account or to a group or organization.

  3. Container Repository: A container repository is a collection of container images that are linked together to offer diverse applications.

Docker Engine

  • Docker Daemon

  • Docker CLI

  • REST API

Docker Architecture

Docker is built on a client-server model. The Docker client communicates with the Docker daemon, which is in charge of constructing, operating, and distributing your Docker containers.

  1. Docker Client: The Docker Client component is what allows developers and users to interface with the Docker platform. The Docker Client can exist on the same host as the Docker daemon. If that fails, the client can connect to a daemon running on a distant computer. A docker client wants to talk to one or more daemons.

  2. Docker Daemon: It receives API requests from the Docker client and handles Docker objects such as images, containers, networks, and volumes.

  3. Docker Registries: Docker Registries are similar to the site where all Docker Images are kept. There is no restriction on the registers being public or private docker registries. Developers can set up their private registers with optimal parameters. Docker Hub is a platform's default registry that stores docker images. It is open to the public and free of charge.

  4. Docker Host: Docker Host promises to provide a ready-to-use environment for running and executing apps. Docker Host is made up of Docker images, daemons, networks, storage, and containers. Host networking provides distinct benefits to Docker Host and the platform as a whole.

  5. Docker CLI: A command line interface for interacting with the Docker daemon. Docker CLI makes it easier to manage your container instances.

  6. REST API: As the name implies, it refers to a specific API that programs use to interface or interact with the Docker daemon. An HTTP client can be used to access the REST API. This API instructs the Docker daemon on how to function within the engine and architecture.

Docker Objects

  1. Dockerfile: A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. This file can be used to create Docker Image. These images can be pulled to create containers in any environment. When you run the docker image, you get docker containers.

  2. Docker Image: A Dockerfile, a text file with a simple, well-defined syntax, describes a Docker image. A picture has no states and does not change. Docker Engine is the basic Docker technology that allows images and containers to run. Docker Images encourages developers to collaborate with docker containers.

  3. Containers: A container is a runnable instance of an image. The Docker API or CLI may be used to manage containers. You may attach storage to a container, link it to one or more networks, or even create a new image based on the current one's state.

  4. Storage: It describes your capacity to store data within the container's writable layer. But you'll need a storage driver for that. Because the storage is non-persistent, the data will be lost if the container is not running.

  5. Network: Docker Networking allows you to set up a network of Docker containers that are managed by a master node known as the manager. The programs that operate outside of Docker will connect to them from outside the host by utilizing the local host and port No.

Commands

  1. docker version: Echoes the Client’s and Server’s Version of Docker.

  2. docker images: List all Docker images.

  3. docker build <image>: Builds an image from a Docker file.

  4. docker save <path> <image>: Saves Docker image to .tar file specified by path.

  5. docker run: Runs a command in a new container.

  6. docker start: Starts one or more stopped containers.

  7. `docker stop: Stops one or more running containers.

  8. docker rmi <image>: Removes Docker image.

  9. docker rm <container_id>: Removes Container.

  10. docker pull: Pulls an image or a repository from a registry.

  11. docker push: Pushes an image or a repository to a registry.

  12. docker export: Exports a container’s filesystem as a tar archive.

  13. docker exec: Runs a command in a run-time container.

  14. docker ps: Show running containers.

  15. docker ps -a: Show all containers.

  16. docker ps -l: Show the latest created container.

  17. docker logs: Show all logs from the container.

  18. docker search: Searches the Docker Hub for images.

  19. docker attach: Attaches to a running container.

  20. docker commit: Creates a new image from a container’s changes.

  21. docker network ls: List networks.

  22. docker network create *network_name*: Create a new network.

Check Kubernetes article for information about Container orchestration.