# Prerequisites

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:

* Ubuntu Impish 21.10
* Ubuntu Hirsute 21.04
* Ubuntu Focal 20.04 (LTS)
* Ubuntu Bionic 18.04 (LTS)

### Install Docker Engine

```shell
sudo apt-get update
```

```shell
sudo apt-get install ca-certificates curl gnupg lsb-release -y
```

> Add Docker’s official GPG key:

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

> Use the following command to set up the stable repository.

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

> Install Docker Engine

```shell
sudo apt-get update
```

```shell
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
```

### Fix Docker .sock file permission issue

```shell
sudo chmod 666 /var/run/docker.sock
```

### Verify that Docker Engine is installed correctly by running the hello-world image

```shell
sudo docker run hello-world
```

> This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.

## Post-installation steps for Linux

The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user `root` and other users can only access it using `sudo`. The Docker daemon always runs as the `root` user.

If you don’t want to preface the `docker` command with `sudo`, create a Unix group called `docker` and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the `docker` group.

> Create the docker group

```shell
sudo groupadd docker
```

> Add your user to the docker group

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

> Log out and log back in so that your group membership is re-evaluated

```shell
newgrp docker
```

> Verify that you can run docker commands without sudo

```shell
docker run hello-world
```

If you get `/home/user/.docker/config.json: permission denied`

```shell
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
```

## Configure Docker to start on boot

```shell
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
```

Test the installation

```shell
docker version
```

## Install Docker Compose

Run this command to download the current stable release of Docker Compose

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

> Please visit Docker website to collect latest version of Docker Compose

[https://docs.docker.com/compose/install](https://docs.docker.com/compose/install/)

Apply executable permissions to the binary

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

> If the command docker-compose fails after installation, check your path. You can also create a symbolic link to /usr/bin or any other directory in your path.

```shell
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
```

Optionally, install `command completion` for the `bash` and `zsh` shell.

```shell
sudo curl \
    -L https://raw.githubusercontent.com/docker/compose/1.29.2/contrib/completion/bash/docker-compose \
    -o /etc/bash_completion.d/docker-compose
```

Test the installation

```shell
docker-compose --version
```

> To uninstall Docker Compose

```shell
sudo rm /usr/local/bin/docker-compose
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.akhaura.info/install-docker-engine-and-docker-compose-on-ubuntu/prerequisites.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
