Diving into Docker: A Journey through Container Enchantment

Diving into Docker: A Journey through Container Enchantment

ยท

4 min read

What is docker ๐Ÿค”โ“

  • Docker is a Linux-based, open-source containerization platform that developers use to build, run, and package applications for deployment using containers

  • Imagine Docker to be a magical box that contains everything your application requires to run smoothly regardless of where it goes. It's like a handy lunchbox that stores your favourite meal, snacks, and drink so you're always ready for a tasty feast, just like your app is always ready to work its magic.

Understanding Containers ๐Ÿ˜ตโ€๐Ÿ’ซ

  • Containers are the enchanting part of Docker! Picture them as mini virtual machines, but instead of running a whole operating system, containers run just your app and its dependencies.

  • This way, they're super lightweight and incredibly fast! It's like having tiny magic boxes for each of your apps, keeping them separate from one another, so they don't mess with each other's work

How Docker Differs from Virtual Machines :

  • Virtual machines are heavyweight, needing a full operating system for each app, while containers share the host system's resources. Docker's containers are so light that they can spin up in a snap, making your apps work like magic.

  • Virtual machines can take a while to start, but Docker's containers are like a swift magician! They start almost instantly, ensuring you never wait long for your apps to launch.

Docker Architecture

  • Docker Client: This is the command-line tool (or a GUI-based interface) that allows users to interact with Docker. Users can issue commands to manage Docker containers, images, networks, and other resources using the Docker Client.

  • A REST API supports interactions between the client and the daemon.

  • Docker Daemon: The Docker Daemon is the core component of Docker that runs as a background service on the host system. It is responsible for managing Docker objects, such as containers, images, volumes, and networks. The Docker Daemon listens for incoming Docker Client requests and executes them.

  • Docker Images: Docker Images are read-only templates that contain everything needed to run an application, including the code, dependencies, libraries, environment variables, and other configurations. Images are used as a basis to create Docker containers.

    • You can get images from DockerHub or create your own images by including specific instructions within a file called Dockerfile.
  • Docker Containers: Docker Containers are instances created from Docker Images. They are lightweight, portable, and isolated runtime environments for running applications. Each container runs as a separate process on the host system, ensuring isolation and consistency.

  • Docker Registries: Docker Registries are repositories that store Docker Images. Docker Hub is the default public registry provided by Docker, which hosts a vast collection of official and community-contributed images. Organizations can set up private registries to store their custom images securely.

  • Docker Network: Docker Network enables communication between Docker containers. Containers within the same network can communicate with each other using their container names or IP addresses. Docker provides various network drivers to create different types of networks, such as bridge, overlay, host, and macvlan networks.

  • Docker Volumes: Docker Volumes are used to persist data generated by Docker containers. Unlike containers, which are ephemeral and can be deleted, volumes allow data to be stored and shared between containers even after they are stopped or removed

Benefits of Docker in the SDLC

  • Build. Docker allows development teams to save time, effort, and money by dockerizing their applications into single or multiple modules. By taking the initial effort to create an image tailored for an application, a build cycle can avoid the recurring challenge of having multiple versions of dependencies that may cause problems in production.

  • Testing. With Docker, you can independently test each containerized application (or its components) without impacting other components of the application. This also enables a secured framework by omitting tightly coupled dependencies and enabling superior fault tolerance.

  • Deploy & maintain. Docker helps reduce friction between teams by ensuring consistent versions of libraries and packages are used at every stage of the development process. Besides, deploying an already tested container eliminates the introduction of bugs into the build process, thereby enabling an efficient migration to production.

Docker Commands :

Let's try some of the docker commands

  • docker run : Use the docker run command to start a new container and interact with it through the command line

  • docker inspect : Use the docker inspect command to view detailed information about a container or image. Syntax: docker inspect <image name>

  • docker port : Use the docker port command to list the port mappings for a container

    Eg: docker port CONTAINER [PRIVATE_PORT[/PROTO]]

  • docker stats : Use the docker stats command to view resource usage statistics for one or more containers

  • docker top : Use the docker top command to view the processes running inside a container . Eg: docker top CONTAINER

  • docker save : Use the docker save command to save an image to a tar archive.

    Eg: docker save > name.tar

  • docker load : Use the docker load command to load an image from a tar archive

    Eg: docker < name.tar

ย