Skip to main content

Command Palette

Search for a command to run...

Containerization Explained: A Practical Guide Using Docker

Published
4 min read
Containerization Explained: A Practical Guide Using Docker

In modern days, not only developers but also students use a shared environment to develop software when working as a team or collaborating with each other. When using shared environments, they may use devices with different versions of development tools, or they may use different libraries to develop the software. This can lead to software crashes because sometimes one person’s pushed version may not be compatible with another person’s version when pulled.

For example, there is Person A and Person B, and they are using Java to develop software. Person A has an older version of Java, while Person B has the latest stable version. When Person B pushes the code to the main branch, some new libraries and files used by the newer Java version will also be pushed. When Person A pulls the code, those libraries and files will also be pulled, but the older Java version may not recognize them. This will cause the software to crash on Person A’s device.

As the example above shows, using a shared environment for development can be very complicated. I have personally experienced this problem when I developed a Java-based application with my teammates for a first-year university assignment. When we finally pushed and merged the application just before the viva, it was runnable on only one laptop. Because of this issue, some of us almost lost our project marks. Fortunately, we had a backup copy, so we managed to survive the crisis.

To overcome these issues, there is a simple and effective method called Containerization. In containerization, we create a container (or a box) and include all the required code, dependencies, environment configurations, and libraries needed to run the application. Then, we share the blueprint of the container with team members so that they can create identical containers on their own devices.

Containerization is similar to packing a travel bag. You make a list of essential items for your journey, such as a toothbrush, soap, clothes, and a water bottle, and pack them into a bag. You then share the list with your friends so they can pack the same items. In this analogy, the container is the bag, and the blueprint is the list of items.

Many of you may know or have heard the word Docker. Docker is one of the most popular open-source platforms that allows you to automate the deployment, scaling, and management of applications using containerization.

The above images show how Docker works and illustrate the architecture of the Docker Engine. The three main components of Docker are:

  • Image – The blueprint or template used to create a container

  • Container – The runtime environment that contains all the requirements to run the application

  • Registry – A storage system used to store and distribute Docker images (e.g., Docker Hub, Amazon ECR, Artifact Registry, Azure Container Registry)

We use the Docker CLI to create, run, and delete Docker resources. Below are some commonly used Docker commands.

docker --version              # Check Docker version
docker pull <image_name>      # Download an image
docker images                 # List images
docker run <image_name>       # Run a container
docker ps                     # List running containers
docker ps -a                  # List all containers
docker stop <container_id>    # Stop a container
docker rm <container_id>      # Remove a container
docker rmi <image_id>         # Remove an image

When using multiple Docker containers, communication between them can be difficult. To enable interaction between containers, Docker networks are used. Below are some basic Docker network commands.

docker network ls                         # List networks
docker network create <network_name>     # Create a network
docker network inspect <network_name>    # Inspect a network
docker network rm <network_name>          # Remove a network
docker run --network <network_name> <image_name>

Conclusion

Containerization provides a reliable solution to problems caused by inconsistent development environments. By packaging applications with all their dependencies, containerization ensures that software runs consistently across different systems. Docker simplifies this process by offering an easy-to-use platform for creating, managing, and deploying containers. As a result, containerization improves collaboration, reduces environment-related issues, and increases development efficiency, especially in team-based projects.

References

Docker Documentation – Docker Overview
https://docs.docker.com/get-started/docker-overview

Freepik – Images and Illustrations
https://www.freepik.com

Udemy Course: Java Spring Boot Microservices with Spring Cloud, Kubernetes & Docker
(This course contains a section where Docker is clearly explained)
https://www.udemy.com/course/java-spring-boot-microservices-with-spring-cloud-k8s-docker