Docker Installation
Server Management

Installing Docker and Docker Compose on Ubuntu

Install Docker Engine and the Docker Compose plugin on an Ubuntu server from the official repository. Using Docker without sudo, your first container and a sample docker-compose.yml.

  • MerkezHost Technical Team
  • 3 min read
  • Level: Intermediate
  • Updated:

Docker lets you run applications together with their dependencies in isolated containers. In this guide we'll install Docker Engine and the Docker Compose plugin on an Ubuntu server from Docker's official repository, then run your first container.

Requirements

  • A KVM-based VDS or dedicated server running Ubuntu 22.04 or 24.04.
  • A user with sudo privileges.
Info

The docker.io package in the Ubuntu repositories is usually an older version. For the latest version and the Compose plugin, we recommend using Docker's official repository.

Step 1: Remove old packages

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove -y $pkg; done

Step 2: Add Docker's official repository

sudo apt-get update
sudo apt-get 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-get update

Step 3: Install Docker Engine and Compose

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

Verify the installation:

sudo docker run hello-world
docker --version
docker compose version

Step 4: Use Docker without sudo

sudo usermod -aG docker $USER
newgrp docker
docker ps
Warning

Users in the docker group effectively have root privileges. Only add users you trust to this group.

Step 5: Your first Compose project

Let's bring up a simple Nginx web server with Compose:

mkdir ~/ilk-proje && cd ~/ilk-proje
nano docker-compose.yml
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/share/nginx/html:ro
    restart: unless-stopped
mkdir html && echo "<h1>Merhaba Docker!</h1>" > html/index.html
docker compose up -d
docker compose ps

When you open http://SUNUCU_IP_ADRESI:8080 in your browser, you'll see your page.

Frequently used commands

docker ps -a                 # List all containers
docker logs -f KONTEYNER     # Follow logs live
docker compose down          # Stop and remove the project
docker system prune -a       # Clean up unused images and containers
Tip

Docker manages firewall rules for published ports itself and can bypass UFW rules. Bind services that should only be reachable locally to the local address, like "127.0.0.1:8080:80".

Conclusion

Your Docker environment is ready. Container workloads benefit greatly from high single-core performance and fast disks, which makes our AMD Ryzen 9 performance servers an excellent choice for Docker.

Frequently Asked Questions

Can I run Docker on an OpenVZ server?

Docker requires a KVM-based virtual server. MerkezHost VDS servers use KVM virtualization, so Docker runs without any problems.

What is the difference between docker-compose and docker compose?

The old docker-compose was a separate Python tool. In current versions, Compose is a plugin of the Docker CLI and is used with the docker compose command (with a space).

  • #docker
  • #docker compose
  • #ubuntu
  • #containers
  • #devops
Share:
Read More

Related Guides