🛥️ Introduction to Docker: Core Concepts
Ravin Rau

Ravin Rau @juniourrau

About: Curiosity makes exploring more interesting. A JavaScript avid with so many questions about life.

Location:
Kuala Lumpur, Malaysia
Joined:
May 8, 2021

🛥️ Introduction to Docker: Core Concepts

Publish Date: Jan 13
234 16

Docker is like a magic toolbox for developers. It lets them build, ship, and manage their apps in tiny, portable boxes called containers. Containers are like virtual rooms, but they are way faster and more efficient than traditional virtual machines (VMs). Thanks to Docker, containers have become super popular, and they’re now a must-have part of modern software development.


What is Docker?

Docker Container

Docker is an open-source platform that automates the deployment of applications inside containers. Containers are isolated environments that contain everything needed to run an application, including the code, runtime, libraries, and system tools. Docker provides developers with tools to build, manage, and distribute these containers.


OCI

What is the Open Container Initiative (OCI)?

The Open Container Initiative (OCI) is an open governance structure established in 2015 by the Linux Foundation. It aims to create industry standards for container runtime and image specifications, ensuring interoperability across container ecosystems.

Docker originally developed its own container runtime and image formats. However, the rise of containers and the need for broader standardization led Docker to contribute its container runtime technology, runc, to the OCI. Today, Docker’s ecosystem adheres to OCI standards, making Docker containers compatible with other OCI-compliant runtimes and tools.

By aligning with OCI standards, Docker ensures that its containers and images can run across various platforms and tools, fostering a more open and collaborative container ecosystem.


Why are Containers Useful?

  1. Portability: Containers can run on any system that supports OCI-compliant runtimes, ensuring that applications behave consistently across environments.
  2. Efficiency: Containers share the host system's kernel, making them lightweight and fast to start compared to VMs.
  3. Scalability: Containers can be easily scaled up or down to handle varying loads.
  4. Consistency: Containers reduce the "it works on my machine" problem by encapsulating all dependencies and configurations.

Containers vs. Virtual Machines vs. Bare Metal

Container vs VMs vs Bare Metal

Bare Metal:

  • Runs directly on physical hardware without any virtualization.
  • Offers maximum performance and direct access to hardware resources.
  • Best suited for high-performance workloads and applications that require complete control over hardware.

Bare Metal

Virtual Machines (VMs):

  • Include a full OS, making them heavier.
  • Require more resources and take longer to start.
  • Suitable for running multiple OS environments on a single physical machine.

Virtual Machines (VMs)

Containers:

  • Share the host OS kernel, making them lightweight.
  • Use less memory and start quickly.
  • Ideal for microservices and rapid deployments.

Container

Aspect Containers Virtual Machines Bare Metal
Resource Efficiency High Moderate Highest
Startup Time Seconds Minutes N/A
*Isolation * Process-level Full OS-level Complete physical isolation
Portability Very High Moderate Low
Performance Near-native Moderate Native
Use Cases Microservices, CI/CD pipelines Legacy applications, OS testing High-performance computing

Docker Terminology

Docker Terminology

  • Dockerfile: A text file with instructions for building a Docker image.
  • Image: A read-only template used to create containers. Images are built from a Dockerfile and follow OCI image specifications.
  • Container: A runnable instance of an image. Containers can be started, stopped, and deleted.
  • Registry: A repository for Docker images. Docker Hub is a popular public registry, and other OCI-compliant registries include Harbor and Quay.

Docker Command Line Cheat Sheet

Docker Command Line Cheat Sheet

0. Basic Docker Commands

  • docker --version: Check Docker version.
  • docker help: Show Docker commands and options.
  • docker info: Display system-wide information about Docker.

1. Images

  • docker images: List all local images.
  • docker pull <image>: Download an image from Docker Hub.
  • docker build -t <image_name> .: Build an image from a Dockerfile in the current directory.
  • docker rmi <image>: Remove an image.
  • docker tag <source_image> <new_image>: Tag an image with a new name.

2. Containers

  • docker run <image>: Run a container from an image.
  • docker run -it <image>: Run a container in interactive mode.
  • docker run -d <image>: Run a container in detached mode.
  • docker ps: List running containers.
  • docker ps -a: List all containers (including stopped ones).
  • docker stop <container>: Stop a running container.
  • docker start <container>: Start a stopped container.
  • docker restart <container>: Restart a container.
  • docker rm <container>: Remove a stopped container.
  • docker exec -it <container> <command>: Run a command inside a running container.

3. Container Management

  • docker logs <container>: View logs of a container.
  • docker top <container>: Display the processes running in a container.
  • docker stats <container>: Display a live stream of resource usage statistics.
  • docker inspect <container>: View details about a container or image.
  • docker rename <old_name> <new_name>: Rename a container.

4. Networking

  • docker network ls: List all Docker networks.
  • docker network create <network_name>: Create a new network.
  • docker network connect <network> <container>: Connect a container to a network.
  • docker network disconnect <network> <container>: Disconnect a container from a network.
  • docker network inspect <network>: View details about a network.

5. Volumes

  • docker volume ls: List all volumes.
  • docker volume create <volume_name>: Create a volume.
  • docker volume inspect <volume>: Display detailed information about a volume.
  • docker volume rm <volume>: Remove a volume.

Example: Creating a Simple Docker Container

Let's create a simple Docker container that runs a Python script.

  1. Create a Python Script: Save the following code in a file named app.py:
   print("Hello, Docker!")
Enter fullscreen mode Exit fullscreen mode
  1. Create a Dockerfile: Create a file named Dockerfile with the following content:
   FROM python:3.9-slim
   COPY app.py /app.py
   CMD ["python", "/app.py"]
Enter fullscreen mode Exit fullscreen mode
  1. Build the Docker Image:
   docker build -t python-app .
Enter fullscreen mode Exit fullscreen mode
  1. Run the Docker Container:
   docker run python-app
Enter fullscreen mode Exit fullscreen mode

This will output:

   Hello, Docker!
Enter fullscreen mode Exit fullscreen mode

Conclusion

Docker makes building, deploying, and running apps using containers is a breeze. By following the OCI standards, Docker ensures everything works together seamlessly in the container world. Containers are super efficient, portable, and scalable, which is why they’re at the heart of modern software development. If you know Docker and how it works with OCI, you can use this tech to speed up your workflows and ensure your apps work on any platform.

Next week I will dive into the docker architecture, so stay tune.

Comments 16 total

  • Mercy
    MercyJan 13, 2025

    Actually, the article I've looking for👏

    • Ravin Rau
      Ravin RauJan 14, 2025

      Thank you very much. Glad it help you, will be making a series for docker. Next will be about its architecture.

      • Mercy
        MercyJan 14, 2025

        Well, I am looking forward to it

  • huviju
    huvijuJan 14, 2025

    Interesting article, are you planning to make this as a series ? I believe there is more to docker that just these information.

    • Ravin Rau
      Ravin RauJan 14, 2025

      Thank you very much @huviju410, yes I am planning to make a series for this since there is a lot of topics that I can cover with docker. There is the docker architecture, docker network, container,registry from each cloud provider and many more.

  • Amit Prajapati
    Amit PrajapatiJan 14, 2025

    Good

  • Austintrim Patches
    Austintrim PatchesJan 14, 2025

    Learn the core concepts of Docker, including containers, images, and orchestration, to streamline your development workflow. Dive into this introduction to understand how Docker can enhance your software deployment process. pvc patches

  • Rookie Sideloader
    Rookie SideloaderJan 14, 2025

    The post covers Docker basics, including Dockerfile creation, container management, and various Docker commands to help you get started. We even walked through an example of creating a simple Docker container to run a Python script.

    For those looking to unlock their full potential in technology, Docker is a great tool to explore. By following the next steps outlined in the post and adhering to OCI standards, you can streamline your workflows and build cross-platform apps with ease.

    Additionally, for gaming enthusiasts seeking ways to sideload apps and games, feel free to explore Rookie Side Loader for helpful guides and tips on enhancing your gaming experience!

  • Jonas Scholz
    Jonas ScholzJan 14, 2025

    I like your graphics, how are you making them?

  • Sahil
    SahilJan 15, 2025

    Thanks a lot mate!

  • Ömer Berat Sezer
    Ömer Berat SezerJan 16, 2025

    This is a clear introduction on Docker! Fantastic drawings! Thanks for sharing. 😊 If you're looking for additional resources, I recently put together a detailed Docker series that complements what’s discussed here. It includes step-by-step hands-on exercises for practical learning (dockerizing flask, nodejs). Feel free to check it out Docker Tutorial, Docker Compose file with Nodejs, Flask, Postgresql, Dockerizing Flask App I’d love to hear your feedback if you get a chance to explore it!

Add comment