
# How to install Docker on Ubuntu 24.04 with Docker Compose

**How to install Docker on Ubuntu 24.04: remove conflicting packages, add Docker's official apt repository with its GPG key, and run `sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin`.** That same command installs Docker Compose as a plugin, so there's nothing extra to set up. As of Nov 20, 2026 the repository ships Docker Engine 29.10 and Docker Compose 5.8. The whole process takes about five minutes.


Prompt for your AI agent:


```text
Create an s1-2 server with Ubuntu 24.04 and hourly billing on 0x.cloud. Show the dry_run price and wait for my "yes". Install Docker Engine and the Docker Compose plugin from Docker's official repository following docs.docker.com, add my user to the docker group, configure log rotation and send me the output of docker version and docker compose version.
```


## Requirements and plan

- 64-bit Ubuntu 24.04 LTS (Noble). 22.04, 26.04 and 26.10 are supported too;
- a sudo user (see [how to add a sudo user on Ubuntu](https://0x.cloud/kb/security/add-sudo-user-ubuntu));
- s1-2 (1 vCPU, 2 GB RAM, 30 GB NVMe, $7.99/mo) runs a few containers; for several services with databases choose s2-4 (4 GB RAM, $15.99/mo). Options are on [Docker VPS hosting](https://0x.cloud/docker-vps-hosting).

Docker Engine itself idles at around a hundred MB; your containers are what use memory. So size the plan by what you'll run: n8n, a bot and Nginx fit in 2 GB, while PostgreSQL, Redis and an app together want 4 GB. You can start on hourly billing: s1-2 is $0.054725 an hour ($7.99 / 730 × 5) and never more than $7.99 in a calendar month. Setup is $0.


[Deploy to 0x.cloud](https://0x.cloud/cabinet/create?plan=s1-2&app=docker)


## Prepare the server

Open the web console of the server in your cabinet (an agent runs the same commands with `run_command`) and remove packages that conflict with Docker's official ones:

```bash
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)
```

`dpkg --get-selections` finds which of those packages are installed and `apt remove` removes them. If none are installed, apt says so and that's fine. Images and volumes in `/var/lib/docker` are kept.

## How to install Docker on Ubuntu 24.04 from the official repository

**Step 1. Add the repository key.**

```bash
sudo apt update
sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
```

These commands create the keyrings folder, download Docker's GPG key and make it readable, so apt can verify package signatures.

**Step 2. Add the repository.**

```bash
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
```

This deb822-format file adds Docker's stable channel. The codename (`noble`) and architecture (`amd64` or `arm64`) are filled in automatically.

**Step 3. Install the packages.**

```bash
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

| Package | What it is |
|---|---|
| `docker-ce` | Docker Engine (the daemon) |
| `docker-ce-cli` | the `docker` command |
| `containerd.io` | the container runtime |
| `docker-buildx-plugin` | BuildKit image builds |
| `docker-compose-plugin` | Docker Compose v2 (`docker compose`) |

**Step 4. Verify.**

```bash
sudo docker run hello-world
docker compose version
sudo systemctl is-enabled docker
```

`hello-world` pulls a test image and prints "Hello from Docker!". `docker compose version` prints `Docker Compose version v5.8.0` or newer. The last command should print `enabled`, meaning Docker starts at boot.

## One-command install with the convenience script

For test servers there's an official script:

```bash
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh --dry-run
sudo sh get-docker.sh
```

`--dry-run` prints what the script would do without changing anything. Docker's docs recommend reviewing scripts before running them and not using this one for upgrades.

## Run Docker without sudo

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

`usermod -aG docker` adds you to the docker group and `newgrp` applies it without logging out. `docker ps` without sudo should print an empty table with a `CONTAINER ID` header, not `permission denied`. Membership in the docker group is root-equivalent, so only add users you trust.

## Docker Compose: your first project

```bash
mkdir ~/hello && cd ~/hello
nano compose.yaml
```

```yaml
services:
  web:
    image: nginx:alpine
    restart: unless-stopped
    ports:
      - "127.0.0.1:8080:80"
```

```bash
docker compose up -d
curl -I http://127.0.0.1:8080
docker compose down
```

`up -d` starts services in the background, `curl -I` checks the response, and `down` stops and removes the containers. Note the `127.0.0.1:` prefix: Docker publishes ports around ufw, so without it the service is open to the internet. The UFW guide explains this in detail. For a real-world example with a domain and HTTPS, see how to self-host n8n.

## Rotate container logs

Container logs grow without limit by default. Cap them:

```bash
sudo nano /etc/docker/daemon.json
```

```json
{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}
```

```bash
sudo systemctl restart docker
```

Each container now keeps at most three 10 MB log files. Check with `docker info --format '{{.LoggingDriver}}'`, which prints `json-file`; a JSON typo stops the service from starting, and `systemctl status docker` shows why. The setting applies to new containers; recreate existing ones with `docker compose up -d --force-recreate`.

## Update Docker

Docker updates with the rest of the system:

```bash
sudo apt update && sudo apt upgrade -y
```

To pin a version, list them with `apt list --all-versions docker-ce` and install `docker-ce=<version>`. For a web UI to manage containers, try Portainer.

## Back up container data

Important data lives in volumes. Archive one with:

```bash
docker run --rm -v VOLUME_NAME:/data -v "$PWD":/backup alpine tar czf /backup/volume-$(date +%F).tar.gz -C /data .
```

`docker volume ls` lists volumes. Keep `compose.yaml` and `.env` in Git (secrets elsewhere). On 0x.cloud you can also enable daily server backups (+20% of the plan price) and $0.99/mo snapshots.

## Troubleshooting

| Error | Fix |
|---|---|
| `permission denied while trying to connect to the Docker daemon socket` | Use `sudo` or add yourself to the docker group |
| `docker-compose: command not found` | Compose v2 is `docker compose`, with a space |
| `NO_PUBKEY` on `apt update` | The key didn't download. Repeat step 1 |
| `Conflicts: docker.io` | Remove old packages with the command in "Prepare the server" |
| A container port is open even though ufw blocks it | Publish it as `127.0.0.1:port:port` |
| Disk is full | Run `docker system df`, then `docker system prune` to remove unused images |

Official guide: [Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/).

0x.cloud servers are in Warsaw with unmetered traffic up to 1 Gbps (image pulls cost nothing extra). Support answers in about 30 minutes on average during business hours (06:00–20:00 UTC), and an OS reinstall costs $0 if an experiment goes wrong.

## FAQ

**Do I need to install Docker Compose separately?**
No. Compose v2 ships as the docker-compose-plugin package alongside Docker Engine and runs as docker compose (with a space). The old hyphenated docker-compose isn't needed.

**What's the difference between docker.io and docker-ce?**
docker.io is packaged by Ubuntu and lags behind Docker releases. docker-ce comes from Docker's official repository and gets updates first. Don't install both: they conflict.

**Why does Docker ignore my ufw rules?**
Docker writes its own iptables rules for published ports, and they're evaluated before ufw. Publish internal ports on 127.0.0.1 only, for example 127.0.0.1:5432:5432.

**How do I run docker without sudo?**
Add your user to the docker group with sudo usermod -aG docker $USER and log in again. Keep in mind this grants root-equivalent access.

**Can I install Docker with a single command?**
Yes, with the official get.docker.com script. It does the same as the repository method, but Docker's docs advise reviewing it first and not relying on it for production upgrades.


[Deploy to 0x.cloud](https://0x.cloud/cabinet/create?plan=s1-2&app=docker)



[Create server: s1-2, $7.99/mo](https://0x.cloud/cabinet/create?plan=s1-2)
