Docker & Containers

Installing Docker and Docker Compose on Ubuntu

Get Docker up and running on your Linux server — includes Docker Compose and your first container.

Published Mar 25, 2025Updated May 25, 20268 min readBeginner
Table of Contents

Why Docker?

Docker packages your application and all its dependencies into a portable container. You can run the same container on any server without worrying about environment differences, conflicting library versions, or complex setup scripts.

Step 1: Remove Old Docker Versions

apt remove docker docker-engine docker.io containerd runc 2>/dev/null

Step 2: Install Docker Engine

apt update
apt install ca-certificates curl gnupg -y

# Add Docker's official GPG key
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |   gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

# Add the Docker repository
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" |   tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
apt update
apt install docker-ce docker-ce-cli containerd.io   docker-buildx-plugin docker-compose-plugin -y

Step 3: Run Docker Without sudo

usermod -aG docker $USER
newgrp docker

Step 4: Verify Installation

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

Step 5: Enable Docker on Boot

systemctl enable docker
systemctl start docker

Your First Real Container — Nginx

# Run Nginx on port 80
docker run -d -p 80:80 --name webserver --restart unless-stopped nginx

# View running containers
docker ps

# View container logs
docker logs webserver

# Stop and remove
docker stop webserver
docker rm webserver

Docker Compose Example

Create docker-compose.yml:

version: '3.8'
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - ./html:/usr/share/nginx/html
    restart: unless-stopped

  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: strongpassword
      MYSQL_DATABASE: myapp
    volumes:
      - db_data:/var/lib/mysql
    restart: unless-stopped

volumes:
  db_data:
docker compose up -d      # Start in background
docker compose ps         # Check status
docker compose logs -f    # Follow logs
docker compose down       # Stop everything
DockercontainersUbuntuDocker Compose
Was this article helpful?

Join Our Discord

Connect with our community of gamers and developers

Get instant support, share experiences, and stay updated with the latest news

Join Us On Discord
2026 VPS SaleLIMITED TIME
View Sale Plans