Understanding Docker: Containers, Images, and How They Work

Hi, ubi's here!

Speaking of Docker, I actually learned a bit about it in Zoomcamp Module 1. But turns out, I struggled to keep up with the material because I wasn’t really solid on the Docker concepts themselves. So, I decided to properly grasp the fundamentals of Docker first, then reconsider whether I want to continue the Zoomcamp course or not.

Here’s my references:

  1. Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
  2. ChatGPT

What is Docker?

According to Mbak Nana, Docker is basically a virtualization tool. There are many types of virtualization tools—another example is Virtual Machines (VMs). She mentioned that the difference between Docker and VMs lies in which layer is being virtualized. VMs virtualize both the OS (Operating System) and the applications running on it. Meanwhile, Docker only virtualizes the application itself.

If you've ever used a VM, you’d know it’s quite heavy (takes up a lot of storage) and requires installing a specific OS (e.g., Linux).

So, what is a container?

If I were to use an analogy, a container is like a truck that carries a single item (called an Image). The only job of this truck is to "run" based on what it’s carrying. In Docker, a container’s sole responsibility is to run a single Image (e.g., MySQL).

What if a project needs multiple components (Python, MySQL, etc)?

That means we need multiple Images running in their respective containers (simultaneously). To make them run together, we have to configure it using docker-compose.yml.

Docker Images can be obtained from DockerHub. The Images available there can be seen as ready-to-use templates—so we don’t have to set everything up from scratch, just run the docker pull command.

Key points to note:

  • Image = A standalone, executable package of software (e.g., MySQL) that includes everything needed to run the application.
  • Container = An active instance of an Image.
  • A container is not a collection of Images, but large applications are usually made up of multiple containers that are connected to each other, with each container being created from a single Image.

After double-checking with ChatGPT multiple times, I realized I had been misunderstanding the concept of containers this whole time. I thought a container would run everything in one place 😭.

Tbh, finally learning this stuff is such a relief. I'm no longer in the wrong path!

Post a Comment