> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opus-host.de/llms.txt
> Use this file to discover all available pages before exploring further.

# Install Docker and Docker Compose on Your Free VPS

> Install Docker and Docker Compose on your Opus Host VPS to run containerized apps quickly and cleanly, with no dependency conflicts.

Docker lets you run apps inside isolated containers, so you never have to fight with system-wide dependencies again. Docker Compose adds a simple YAML file for defining multi-container setups. Together, they are the fastest way to deploy pretty much anything on your Opus Host VPS.

## Install Docker

<Steps>
  <Step title="Update the package index and install prerequisites">
    ```bash theme={null}
    sudo apt update
    sudo apt install -y ca-certificates curl gnupg
    ```
  </Step>

  <Step title="Add Docker's official GPG key and repository">
    ```bash theme={null}
    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
      sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    sudo chmod a+r /etc/apt/keyrings/docker.gpg

    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
      https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    ```
  </Step>

  <Step title="Install Docker Engine and Compose">
    ```bash theme={null}
    sudo apt update
    sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    ```
  </Step>

  <Step title="Verify the installation">
    ```bash theme={null}
    sudo docker run hello-world
    docker compose version
    ```
  </Step>
</Steps>

## Run Docker without sudo

Add your user to the `docker` group so you can run `docker` commands without `sudo`:

```bash theme={null}
sudo usermod -aG docker $USER
```

Log out and back in for the change to take effect.

<Warning>
  Anyone in the `docker` group effectively has root access to the host. Only add trusted users.
</Warning>

## Your first Compose stack

Create a folder for your project and a `docker-compose.yml` file:

```bash theme={null}
mkdir ~/myapp && cd ~/myapp
nano docker-compose.yml
```

Example: an Nginx web server exposed on port 80.

```yaml theme={null}
services:
  web:
    image: nginx:alpine
    ports:
      - "80:80"
    restart: unless-stopped
```

Start it in the background:

```bash theme={null}
docker compose up -d
```

## Common commands

```bash theme={null}
docker ps                 # list running containers
docker compose logs -f    # follow logs
docker compose down       # stop and remove containers
docker compose pull       # update images
docker system prune -a    # free up disk space
```

<Tip>
  Containers survive reboots when you use `restart: unless-stopped` in your compose file. No systemd unit required.
</Tip>
