1080*80 ad

Docker on Debian 10 Buster: Installation and Usage

How to Install and Use Docker on Debian 10 Buster: A Comprehensive Guide

Containerization has fundamentally changed how developers build, ship, and run applications. At the forefront of this revolution is Docker, a powerful platform that allows you to package applications and their dependencies into isolated environments called containers. This ensures your application runs consistently across any system, from a local laptop to a production server.

If you’re running Debian 10 Buster, you’re on a stable and reliable platform perfect for leveraging Docker’s capabilities. This guide will walk you through the entire process, from installation to running your first container, ensuring you have a secure and efficient setup.

Before You Begin: Prerequisites

Before diving into the installation, ensure you have the following in place:

  • A system running Debian 10 Buster.
  • A user account with sudo privileges.
  • An active internet connection to download the necessary packages.

Step-by-Step Guide to Installing Docker on Debian 10

To ensure you have the latest and most secure version, we will install Docker Engine from Docker’s official repository. While Debian’s default repositories may contain a version of Docker, it is often outdated.

Step 1: Update Your System

First, open your terminal and update your package list and upgrade existing packages to their latest versions. This is a crucial first step for system health and security.

sudo apt update
sudo apt upgrade

Step 2: Install Required Packages

Next, install the packages that allow apt to use a repository over HTTPS, which is essential for securely downloading the Docker packages.

sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release -y

Step 3: Add Docker’s Official GPG Key

To ensure the Docker packages you download are authentic and have not been tampered with, you need to add Docker’s official GPG (GNU Privacy Guard) key to your system.

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

This command downloads the key, de-armors it, and stores it in a location where apt can find it for package verification.

Step 4: Set Up the Docker Repository

Now, add the official Docker repository to your system’s APT sources. This tells your system where to find the official Docker packages.

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 5: Install Docker Engine

With the repository configured, update your package list one more time to include the Docker packages, and then install Docker Engine.

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

Step 6: Verify the Installation

Once the installation is complete, the Docker service should start automatically. You can verify its status to confirm that it’s active and running without errors.

sudo systemctl status docker

You should see output indicating the service is active (running).

Essential Post-Installation Step: Running Docker Without Sudo

By default, the Docker daemon binds to a Unix socket owned by the root user. This means you have to use sudo for every Docker command, which can be inconvenient and a potential security risk.

To run Docker commands as a non-root user, you need to add your user to the docker group.

1. Add your user to the docker group:

The docker group is created automatically during installation. Add your current user to this group with the following command:

sudo usermod -aG docker ${USER}

2. Apply the group changes:

For the new group membership to take effect, you must log out and log back in, or you can activate the changes for the current terminal session with this command:

newgrp docker

After this, you can run Docker commands without sudo. You can test this by running a simple command:

docker run hello-world

If successful, Docker will pull the hello-world image and run it in a new container. The container will print a confirmation message and then exit.

Getting Started with Docker: Essential Commands

Now that Docker is installed and configured, let’s cover some of the most common commands you’ll use.

  • Pulling an Image: To download a container image from Docker Hub (the default public registry), use the docker pull command.

    docker pull nginx
    
  • Listing Images: To see all the images you have downloaded to your system, use docker images.

    docker images
    
  • Running a Container: The docker run command is used to create and start a container from an image.

    docker run --name my-web-server -d -p 8080:80 nginx
    
    • --name my-web-server: Assigns a custom name to the container.
    • -d: Runs the container in detached mode (in the background).
    • -p 8080:80: Maps port 8080 on your host machine to port 80 inside the container.
  • Listing Active Containers: To see all running containers, use docker ps.

    docker ps
    

    To see all containers, including stopped ones, add the -a flag: docker ps -a.

  • Stopping a Container: To stop a running container, use docker stop followed by the container’s name or ID.

    docker stop my-web-server
    
  • Removing a Container: Once a container is stopped, you can remove it with docker rm.

    docker rm my-web-server
    
  • Removing an Image: To free up disk space, you can remove images you no longer need with docker rmi.
    bash
    docker rmi nginx

    Note: You must remove all containers based on an image before you can remove the image itself.

By following this guide, you have successfully installed Docker on your Debian 10 system, configured it for secure, non-root access, and learned the fundamental commands to manage containers. You are now ready to explore the vast ecosystem of containerized applications and streamline your development workflow.

Source: https://kifarunix.com/install-and-use-docker-on-debian-10-buster/

900*80 ad

      1080*80 ad