Docker Overview🐳

Docker Overview🐳

What is Docker?

  • Docker is a tool for running applications in an isolated environment.
  • It is similar to Virtual Machine but it's much faster and does not require a lot of memory and an entire operating system to operate.
  • The cool thing about docker is that your application runs in exact same environment for eg. if it works on my machine it will definitely work on your machine, or if it works on the staging environment it will also work in a production environment.

What can I use Docker for?

Docker provides the ability to package and run an application in an isolated environment called containers. Containers are great for continuous integration and continuous deployment (CI/CD) workflows. Using docker you can significantly reduce the delay between writing code and running it in production.

Containers vs VM

Containers

  • containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as an isolated process in userspace.

Virtual Machine

  • An application on a VM requires a guest OS and thus an underlying hypervisor to run. The hypervisor is used to create multiple machines on a host operating system and it manages virtual machines. These virtual machines have their own operating system and do not use the host’s operating system. They have some space allocated. Image description

Docker Architecture

Image description

The Docker daemon

The docker daemon listens to the API requests and manages Docker objects such as images, containers, network, and volumes.

The Docker client

The docker client is the primary way to interact with Docker. When you use the command using docker, the client sends these commands to deamon, which carries them out. The Docker client can communicate with more than one daemon.

Docker Registries

A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use. When you pull the image Docker by default look for it on Docker Hub.

Docker Objects

Images

An image is a read-only template with instructions for creating a Docker container. Often an image is based on another image, with some additional customization. You can create your own images or can use those created and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image.

  • Image is a template for creating an environment of your choice. It is also a snapshot.
  • Images are immutable. Once built, the files making up an image do not change. Images can be stored locally or in remote locations like hub.docker.com.

Containers

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using CLI.

Docker Compose

  • Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. It is a declarative way of describing the components of a Docker application.

Docker Volume and Bind Mounts

  • By default, all the files inside the container are stored on a writable container layer.
  • The data does not persist when the container is no longer running.
  • Docker has two ways to persist data.
    1. Volumes
    1. Bind Mounts

Volumes

  • Volumes are a way to persist data between containers.
  • volumes are stored in a part of the filesystem which is managed by Docker.
  • a given volume can be mounted into multiple containers.
  • when no running container is using the volume, it is still available.

Bind Mounts

  • Bind mounts are stored anywhere on the host system.
  • bind mounts are used to mount a volume from a container into another container.
  • In Bind Mounts, the file or directory is referenced by its full path in the host system.

Image description

To see basic commands like pulling building images etc.click here

Now that you know what docker is you can now create your application with tons of containers that interact with each other so you can imagine the effort to manage hundreds of containers manually, every time a container crashes or the communication between them is not working you have to manually fix these problems. Here is where the container-orchestration system comes into play, It helps in automating application deployment, scaling, and management. One of the very widely used COE is Kubernetes.

connect :twitter

Did you find this article valuable?

Support Shubham Yadav by becoming a sponsor. Any amount is appreciated!