# Docker and Docker Compose Setup

Step 1: Update the Package Index

Open your terminal and run the following command to update your package index:

```bash
sudo apt update
```

#### Step 2: Install Required Packages

Install the necessary packages that allow `apt` to use packages over HTTPS:

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

#### Step 3: Add Docker’s Official GPG Key

Download and add Docker’s GPG key using the recommended method:

```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/docker.gpg > /dev/null
```

#### Step 4: Add the Docker Repository

Add the Docker repository to your system:

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

#### Step 5: Update the Package Index Again

After adding the Docker repository, update the package index again:

```bash
sudo apt update
```

#### Step 6: Install Docker

Now, install Docker:

```bash
sudo apt install docker-ce
```

#### Step 7: Start and Enable Docker

Start the Docker service and enable it to run on startup:

```bash
sudo systemctl start docker
sudo systemctl enable docker
```

#### Step 8: Verify Docker Installation

Check if Docker is installed correctly by running:

```bash
sudo docker --version
```

You should see the installed version of Docker.

#### Step 9: Install Docker Compose

1. **Download the Latest Version of Docker Compose**:

   Find the latest version from the [Docker Compose GitHub releases page](https://github.com/docker/compose/releases). As of now, you can use the following command (replace `v2.14.2` with the latest version if needed):

   ```bash
   sudo curl -L "https://github.com/docker/compose/releases/download/v2.14.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
   ```
2. **Apply Executable Permissions**:

   Make the Docker Compose binary executable:

   ```bash
   sudo chmod +x /usr/local/bin/docker-compose
   ```
3. **Verify Docker Compose Installation**:

   Check if Docker Compose is installed correctly by running:

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

You should see the installed version of Docker Compose.

#### Step 10: Manage Docker as a Non-root User (Optional)

If you want to run Docker commands without `sudo`, you can add your user to the `docker` group:

1. **Add Your User to the Docker Group**:

   Replace `username` with your actual username if you're specifying it:

   ```bash
   sudo usermod -aG docker $USER
   ```
2. **Log Out and Back In**:

   Log out of your current session and back in to apply the group change. Alternatively, you can run:

   ```bash
   newgrp docker
   ```

####


---

# 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://node.z4ch.xyz/tools/docker-and-docker-compose-setup.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.
