Installing Docker on Debian or Ubuntu

Step 1: Install Dependencies

Before installing Docker, make sure your packages are updated and that necessary dependencies are installed.

bash
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

Step 2: Add Docker’s Official GPG Key

Add Docker's GPG key to your system to verify the authenticity of the packages.

bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Step 3: Add Docker Repository

Add the Docker repository to your APT sources list.

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

Step 4: Install Docker Engine

Update your package index and install Docker Engine.

bash
sudo apt update sudo apt install docker-ce -y

Step 5: Verify Docker Installation

Check the status of Docker to ensure it is running.

bash
sudo systemctl status docker

Docker should now be up and running on your server.

Basic Docker Commands

  • Run a Container To start a new container, use the docker run command. For example:

    bash
    sudo docker run hello-world
  • List Running Containers To see all currently running containers:

    bash
    sudo docker ps
  • List All Containers (Including Stopped) To view all containers, including those that are stopped:

    bash
    sudo docker ps -a
  • Run a Container in Interactive Mode To start a container and open an interactive terminal session:

    bash
    sudo docker run -it ubuntu bash
  • Stop a Container To stop a running container:

    bash
    sudo docker stop container_id
  • Remove a Container To remove a container:

    bash
    sudo docker rm container_id

Docker Configuration

  • Add User to Docker Group (Optional) To use Docker without sudo, add your user to the Docker group:

    bash
    sudo usermod -aG docker $USER

    Log out and log back in, or restart your session for the changes to take effect.

Example Usage of Docker

  • Install and Run Nginx To start an Nginx container and map port 80 from the host to the container:

    bash
    sudo docker run -d -p 80:80 nginx
  • Stop and Remove Nginx Container To stop and remove the Nginx container:

    bash
    sudo docker stop container_id sudo docker rm container_id

Conclusion

Docker provides powerful tools for deploying and managing containerized applications. By following the steps above, you can install and start using Docker on your Debian or Ubuntu server.

  • docker, vps, server, debian, ubuntu
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Корпоративная почта на базе собственного домена

Корпоративная почта на собственном домене не только придаёт профессиональный...

Установка и настройка Rclone

Rclone — это мощный инструмент командной строки для управления файлами на облачных хранилищах....

Apache vs Nginx: what’s the difference, how to Install, and which one to choose?

When choosing a web server for your project, Apache and Nginx often come into focus. Both of...

HTTP Errors: common causes and how to fix them

Error 403: ForbiddenDescription: The server understands the request but refuses to fulfill it....

Let's Encrypt without a control panel

Let's Encrypt SSL Certificates: How to Install and Set Up Free Automated Encryption Let's...

Powered by WHMCompleteSolution