Getting Started with Docker: A Beginner’s Guide

Docker Banner image

Getting Started with Docker: A Beginner’s Guide

Docker glowy logo with techy elements
User Logo of a girl

Prerana Maurya

Have you ever moved to a new house? If so, you probably packed your belongings into boxes – clothes in one, kitchenware in another, and so on. Now, imagine if you could do the same thing with your software applications. That’s where Docker comes in, acting like those sturdy shipping containers you see stacked on cargo ships.

Think of Docker containers as virtual boxes for your apps. Instead of scattering your software’s bits and pieces all over your computer like a messy roo, Docker neatly organizes everything into these containers. Each container holds everything your app needs to run smoothly – like files, code, and settings – all bundled up and ready to go.

How would you define Docker in simple terms?

Docker is an open source centralized platform that allows you to package ,distribute and run applications in isolated environments called containers. Containers are like isolated virtual machine that contain everything needed to run the application, including code , dependencies ,libraries etc. Docker is used to create ,deploy and run applications.

How containerization is different from virtualization?

Imagine you’re planning a party, and you need a space to host it. You have two options: renting out an entire building or using a versatile party tent.

  1. Virtualization (VMware): Renting out an entire building is like virtualization. You get a big space, and you can divide it into smaller rooms for different activities. Each room is independent and can have its own decorations, music, and guests. However, setting up and tearing down rooms can be time-consuming, and if one room needs more resources, it can’t borrow from others easily.
  2. Containerization (Docker): Using a versatile party tent is like containerization. You have one big space, but you can set up different sections using partitions. Each section is separate, but they all share the same resources, like air conditioning and lighting. If one section needs more space, it can expand, and when it’s not needed, it can shrink back down. This setup is quicker to set up and tear down, and it’s more efficient with resources since they’re shared.

    In the context of software:

Virtualisation V/S Dockerisation
  • Virtualization (VMware): Virtual machines (VMs) emulate full-fledged computers, each with its own operating system (OS) and resources. They’re heavyweight because they include a full OS, making them slower to start up and consume more resources.
  • Containerization (Docker): Containers, on the other hand, share the host OS kernel and only contain the necessary libraries and dependencies for the application to run. They’re lightweight, start up quickly, and consume fewer resources compared to VMs.

Docker uses OS Level Virtualization whereas VM tools uses Hardware Level Virtualization.

So, while both virtualization and containerization provide isolation and flexibility, containerization, like Docker, offers a more lightweight and efficient solution.

Key Benefits of Docker Implementation

Docker brings many advantages to developers and organizations. It ensures consistent environments across platforms, making it portable and efficient. This is thanks to containerization, which packages applications and dependencies into a single container. This container runs the same way everywhere.

Some of the main benefits of using Docker include:

  • Consistent environments across platforms, ensuring portability and efficiency
  • Lightweight and faster than virtual machines, resulting in improved scalability
  • Easily scale applications, making it ideal for large-scale deployments

Docker’s efficiency and scalability are perfect for improving development and deployment. It simplifies the process by reducing the complexity of traditional virtualization. This leads to faster deployment and better efficiency.

Essential Docker Components

To get a better understanding of Docker’s components, it’s helpful to first explore the Dockerization workflow.

Dockerization Workflow

This introduction provides a gentle entry into the concept, ensuring clarity and context for the reader before discussing the specific Docker components.

These components that come together to help to create, manage, and run containers seamlessly.

Here are the main Docker components :-

  1. Docker Daemon / Server / Engine — It is the heart of the docker and it runs on the host OS. It is responsible for running containers to manage docker service.
  2. Docker Client — The Docker Client is a tool that allows you to interact with the Docker Engine. It’s the command-line interface (CLI) you use to send commands to Docker, like building images, running containers, or managing Docker resources. It acts as the user interface to communicate with Docker and perform tasks.
  3. Docker Host — The physical or virtual machine that has Docker installed and runs containers. It acts as the environment where Docker can manage and execute containers.
  4. Docker Images — These are like blueprints or recipes for your app. They contain everything your app needs to run, like the software and settings. When you want to start an app, you use an image to create a container.
  5. Docker Containers — These are the actual running versions of your images. Imagine them as lightweight, self-contained “boxes” where your app runs, with everything it needs packed inside. They’re easy to start, stop, and move around.
  6. Docker Compose — If you need more than one container for your app (like a web server and a database), Docker Compose helps you manage them all together. It lets you define and run multiple containers with a single command, making life easier.
  7. Docker Hub — This is like a giant library or store where you can find, share, and store Docker images. You can download ready-to-use images or upload your own to share with others.

Setting Up Docker

I will show you how to install docker on ubuntu but you can use the official documentation page to install on different OS

In this section, I’ll guide you through installing Docker on Ubuntu. If you’re using a different operating system, feel free to check out the official Docker documentation for installation instructions tailored to your platform.

Steps to Install Docker on Ubuntu

  • Update Your System:
    First, let’s ensure your system is up to date by running the following command in your terminal:
sudo apt update
  • Install Required Dependencies:
    Docker requires a few packages to be installed before we can proceed. Run this command to install them:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
  • Add Docker’s Official GPG Key:

    This step ensures that the Docker packages you’re installing are authentic. Run the following command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • Add Docker Repository:

    Now, add the Docker repository to your system’s package manager so you can install Docker. Use this command:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • Install Docker Engine:

    Update your package list again to include the Docker repository, then install Docker

sudo apt update && sudo apt install docker-ce

 

  • Verify Docker Installation:

    Once the installation is complete, verify that Docker is running properly by checking its version:

docker --version

You should see output showing the Docker version, confirming that the installation was successful.

  • Start and Enable Docker (Optional):
    If Docker isn’t running automatically, you can start it manually with the following command:

sudo systemctl start docker

To make sure Docker starts automatically when your system boots, run:

sudo systemctl enable docker
  • Run Docker Without Sudo (Optional):
    By default, Docker commands require sudo. If you want to run Docker without typing sudo each time, you can add your user to the Docker group:

sudo usermod -aG docker $USER

After running this command, log out and log back in, or restart your system for the changes to take effect.

You can also use the official
docker installation guide

to setup docker engine.

Docker Basic Commands

Now that Docker is installed, let’s explore some essential Docker commands. These commands will help you interact with Docker containers, images, and manage your environment efficiently.

1. Docker Version & System Info

Check if Docker is installed and running correctly:

docker --version

2. Working with Docker Images

  • Search for an image on Docker Hub:

docker search ubuntu
  • Download a Docker image:

docker pull ubuntu
  • List all downloaded images:

docker images
  • Remove a specific image:

docker rmi image_name

3. Running and Managing Containers

  • Run a container from an image:

docker run ubuntu
  • Run a container in interactive mode (attach terminal):

docker run -it ubuntu /bin/bash
  • List running containers:

docker ps
  • List all containers (including stopped ones):

docker ps -a
  • Stop a running container:

docker stop container_id
  • Remove a container:

docker rm container_id

Running Your First Docker Container

Now that you know the essential commands, let’s run your first Docker container!

To ensure everything is working correctly, run the following command:


docker run hello-world

What Happens Here?

  • Docker checks if the hello-world image is available locally.
  • If not found, it downloads the image from Docker Hub.
  • A container is created and executed from the image.
  • The container prints a welcome message and then exits.

This verifies that Docker is correctly installed and ready to use.

Conclusion

Congratulations! 🎉 You’ve successfully installed Docker, learned some basic commands, and even ran your first container. Docker is a powerful tool that simplifies application deployment, making it a must-know for developers and DevOps engineers.

 

In upcoming blogs, we will dive deeper into Docker concepts such as:

✅ Building custom Docker images 📦

✅ Managing data with Docker volumes 💾

✅ Networking in Docker 🌐

✅ Orchestrating containers with Docker Compose 🏗

Stay tuned for more hands-on Docker tutorials! 🚀

Leave a Reply

Blog Content