Docker on Ubuntu
Complete step-by-step masterclass for installing Docker Engine, Desktop, and running Postgres in containers.
Docker Engine + CLI
01
Remove conflicting packages
Purge old unofficial Docker distributions to ensure a clean slate.
sudo apt remove docker.io docker-compose docker-compose-v2 \
docker-doc podman-docker containerd runc 2>/dev/null; echo done
Reading package lists... Done
done
done
02
Setup Docker Repository
Import official GPG keys and configure the stable repository.
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
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
03
Install Docker Packages
Fetch the latest stable Docker Engine, CLI, and plugins.
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
Setting up docker-ce (5:28.x.x~ubuntu...) ...
Created symlink ... docker.service
Created symlink ... docker.service
04
Verify Engine Status
Ensure the background service is active and running.
sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled)
Active: active (running) since ...
Loaded: loaded (/lib/systemd/system/docker.service; enabled)
Active: active (running) since ...
05
Post-Installation Steps
Enable non-sudo access to Docker for a better experience.
sudo usermod -aG docker $USER && newgrp docker
💡
After running this, your current terminal session picks up the new group. No logout required in
most cases.
06
Hello World Deployment
Final confirmation that everything is connected correctly.
docker --version && docker run hello-world
Docker version 28.x.x, build xxxxxxx
Hello from Docker!
This message shows that your installation appears to be working correctly.
Hello from Docker!
This message shows that your installation appears to be working correctly.
Docker Desktop (GUI)
07
Check KVM Support
Verify virtualization support required for Desktop acceleration.
kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
KVM acceleration can be used
💡
If not found:
sudo apt install -y cpu-checker08
Download .deb Package
Fetch the latest desktop binary from the official site.
wget https://desktop.docker.com/linux/main/amd64/docker-desktop-amd64.deb
09
Install Package
Install the GUI application and its dependencies.
sudo apt install ./docker-desktop-amd64.deb
N: Download is performed unsandboxed as root ...
(This warning is harmless and cosmetic)
(This warning is harmless and cosmetic)
10
Launch Desktop
Trigger the user-space service for Docker Desktop.
systemctl --user start docker-desktop
11
Unified Verification
Confirm that both Desktop and Engine are synchronized.
docker compose version && docker version
Docker Compose version v2.x.x
Client: Docker Engine - Community
Server: Docker Desktop
Client: Docker Engine - Community
Server: Docker Desktop
PostgreSQL 16.2
12
Pull Postgres Image
Download the official Docker image for Postgres 16.2.
docker pull postgres:16.2
13
Spin up the Container
Launch Postgres with persistence, custom creds, and port mapping.
docker run -d \
--name pg16 \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=mydb \
-p 5432:5432 \
-v pgdata:/var/lib/postgresql/data \
postgres:16.2
14
Interact via PSQL
Enter the container and run SQL queries in real-time.
docker exec -it pg16 psql -U admin -d mydb
mydb=# SELECT version();
PostgreSQL 16.2 on x86_64-pc-linux-gnu...
PostgreSQL 16.2 on x86_64-pc-linux-gnu...
✅
Postgres is successfully running and accessible!
15
Useful Lifecycle Commands
Common commands for managing your Postgres instance.
docker stop pg16 # Stop container
docker start pg16 # Restart container
docker logs pg16 # View postgres logs
docker volume ls # Confirm persistence volume exists