Post

1. Getting Started with Docker

A step-by-step guide to installing Docker on your system and setting up a basic container. This tutorial is designed for beginners and covers the essentials of Docker.

1. Getting Started with Docker

Introduction

Have you ever encountered a situation where your application works flawlessly on your machine but fails on another? Or faced the daunting task of setting up a new environment, worrying about installing all dependencies and potential version conflicts with other projects? Docker can help! Docker is a platform that allows you to package your application and its dependencies into a container, ensuring it runs consistently across different environments. In this blog post, we’ll guide you through the process of installing Docker on your system and setting up a basic container.

Installation

Before we begin, make sure you have the admin privileges on your system. Otherwise, contact your system administrator to install Docker for you.

I will be installing Docker on Linux system. If you are using a different operating system, please refer to the official Docker documentation for Windows or macOS.

  1. Install Docker on Your System
    • Arch Linux
      1
      
      sudo pacman -S docker
      
    • Ubuntu/Debian
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      
      # Add Docker's official GPG key:
      sudo apt-get update
      sudo apt-get install ca-certificates curl
      sudo install -m 0755 -d /etc/apt/keyrings
      sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
      sudo chmod a+r /etc/apt/keyrings/docker.asc
      # Add the repository to Apt sources:
      echo \
       "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
       $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
       sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
      sudo apt-get update
      # Install Docker:
      sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
      
  2. Start Docker Service After installation, you need to start the Docker service. Run the following command:
    1
    
    sudo systemctl start docker
    
  3. Enable Docker to Start on Boot To ensure Docker starts automatically when your system boots, run the following command:
    1
    
    sudo systemctl enable docker
    
  4. Add Your User to the Docker Group By default, Docker requires root privileges to run. To avoid using sudo every time you run a Docker command, you can add your user to the Docker group. Run the following command:
    1
    
    sudo usermod -aG docker $USER
    

    After running this command, you need to log out and log back in for the changes to take effect.

  5. Verify Docker Installation To verify that Docker is installed correctly, run the following command:
    1
    
    docker run hello-world
    

    This command will download a test image and run it in a container. If everything is set up correctly, you should see a message indicating that Docker is working.

Conclusion

You have successfully installed Docker on your system and verified its functionality. In the next blog post, we will explore how to create and run Docker containers. Stay tuned!

This post is licensed under CC BY 4.0 by the author.