Skip to content
Melinhost

Installing Docker and Docker Compose on Ubuntu, step by step

Install Docker Engine from the official repository, use it without root, run your first container and manage multi-app stacks with Compose.

Tutorials · 3 min read

install-docker-ubuntu

Docker runs applications together with their dependencies inside isolated containers. It is the most practical way to host many services on one server without conflicts. This guide installs Docker Engine and Docker Compose from the official repository on Ubuntu 24.04.

Prerequisites

  • A cloud server running Ubuntu 22.04 or 24.04 and a user with sudo rights (see Connecting with SSH).
  • The system should be up to date: sudo apt update && sudo apt upgrade -y

1. Add the official repository

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

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

2. Install Docker Engine

sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
docker --version
docker compose version

3. Verify the installation

sudo docker run --rm hello-world

If you see “Hello from Docker!” the installation is complete.

4. Use it without root (optional)

sudo usermod -aG docker $USER
newgrp docker
Security note: a user in the docker group effectively has root rights. Add only users you trust.

5. Your first Compose file

Create a folder and write a compose.yaml in it. Example: a simple web server.

services:
  web:
    image: nginx:alpine
    restart: unless-stopped
    ports:
      - "8080:80"
docker compose up -d      # start
docker compose ps         # status
docker compose logs -f    # logs
docker compose down       # stop and remove

At http://SERVER_IP:8080 you will see the Nginx welcome page. For real applications use a reverse proxy instead of exposing ports straight to the internet: automatic HTTPS with Caddy.

Useful commands

CommandWhat it does
docker ps -aLists all containers
docker compose pull && docker compose up -dUpdates images and restarts
docker system dfShows disk usage
docker system prune -aCleans unused images and containers (use with care)

Things to watch

  • Docker can publish ports bypassing the firewall (UFW); publish only the ports you need and put them behind a reverse proxy (the 127.0.0.1:8080:80 form allows local access only).
  • Keep data in volumes, not inside the container; otherwise data is lost when the container is removed.
  • Take regular snapshots and off-server backups.

Start with Melinhost

A cloud server with 4 vCPU and 8 GB RAM is a good start for Docker. Full root access lets you build your environment exactly as you like.

Related posts

err-ssl-version-or-cipher-mismatch

· Tutorials

ERR_SSL_VERSION_OR_CIPHER_MISMATCH: causes and fixes

The browser can’t establish a secure connection: how to find and fix old TLS versions, incompatible ciphers, a missing certificate and wrong virtual-host settings.

Read more →

Cookie preferences

We use cookies required for the site to work. Analytics and marketing cookies are enabled only with your consent. Cookie Policy