How to install the latest Docker and Docker Compose on Debian-based Linux systems?
Tags: docker, compose, linux, elementaryos
Published: 2023-04-22 06:41:03

---
title: How to install the latest Docker and Docker Compose on Debian-based Linux systems?
published: true
description: installation of docker and docker-compose 
tags: docker, compose, linux, elementaryos
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-04-22 06:39 +0000
---
# How to install the latest Docker and Docker Compose on Debian-based Linux systems

In this tutorial, we will install Docker and Docker Compose on Ubuntu. We will first install Docker and then install Docker Compose.

### Installing Docker

1. Update the apt package index and install aptitude:

   ```bash
   sudo apt-get update
   sudo apt-get install aptitude
   ```

2. Install required packages for apt to use HTTPS:

   ```bash
   sudo aptitude update
   sudo aptitude install \
   ca-certificates \
   curl \
   gnupg
   ```

3. Add the Docker GPG key to the keyring:

   ```bash
   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
   sudo chmod a+r /usr/share/keyrings/docker.gpg
   ```

4. Add the Docker repository to the apt sources list:

   ```bash
   echo \
   "deb [arch="$(dpkg --print-architecture)" signed-by=/usr/share/keyrings/docker.gpg] 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
   ```

5. Update the apt package index again and install Docker:

   ```bash
   sudo aptitude update
   sudo aptitude install docker-ce docker-ce-cli containerd.io
   ```

### Adding user to the docker group

1. Create the docker group:

   ```bash
   sudo groupadd docker
   ```

2. Add your user to the docker group:

   ```bash
   sudo usermod -aG docker $USER
   ```

3. Activate the changes to groups:

   ```bash
   newgrp docker
   ```

4. Verify that you can run Docker commands without sudo:

   ```bash
   docker run hello-world
   ```

### Installing Docker Compose

1. Download the Docker Compose binary:

   ```bash
   sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
   ```

2. Apply executable permissions to the binary:

   ```bash
   sudo chmod +x /usr/local/bin/docker-compose
   ```

3. Verify the installation by checking the version of Docker Compose:

   ```bash
   docker-compose --version
   ```

This should output the version number of the latest Docker Compose.

You have now installed Docker and Docker Compose on Debian-based Linux systems.

## Automatic installation

Here's a script that automates the installation of Docker and Docker Compose on Debian-based Linux systems, including adding the current user to the docker group:

Copy the following script into a file, for example, `docker-install.sh`, make it executable with `chmod +x docker-install.sh`, and then run it with `./docker-install.sh`. This will install Docker and Docker Compose, add the current user to the docker group, and verify the installation of both tools.

```bash
#!/bin/bash

# Install Docker and Docker Compose on Debian-based Linux systems
# Include the current user in the docker group

# Install Docker
sudo apt-get update
sudo apt-get install aptitude -y
sudo aptitude update
sudo aptitude install -y \
    ca-certificates \
    curl \
    gnupg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
sudo chmod a+r /usr/share/keyrings/docker.gpg
echo \
    "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] 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 aptitude update
sudo aptitude install -y docker-ce docker-ce-cli containerd.io

# Add the current user to the docker group
sudo groupadd docker
sudo usermod -aG docker $USER

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" \
    -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# Verify the installation
docker --version
docker compose --version
```