Install Docker on a fresh VM

Overview & Details
Overview & Details
Before you begin
Clean VM
Start with a fresh, 64-bit Ubuntu Server LTS virtual machine.
Check Docker’s
supported Ubuntu versions
before choosing your image. Remove any old or unofficial Docker
packages first.
Recommended resources
At least 2 vCPUs, 2 GB of RAM, and 20 GB of disk space. Images,
volumes, and logs grow quickly, so allow more disk for real workloads.
Run with care: Docker runs as root, and anyone in the
docker group effectively has root access to the VM. Use a
VM you control and take a snapshot first.
Connect and update
Sign in to the VM as root and update its packages. Replace the example
IP address with your own.
ssh root@YOUR_SERVER_IP
apt update && apt upgrade -y
Remove conflicting packages
Ubuntu and third-party repositories ship unofficial Docker packages
that conflict with the official ones. This removes them if present;
it is safe if none are installed.
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do apt remove -y $pkg; done
Existing images, containers, and volumes in /var/lib/docker
are not removed by this command.
Add Docker’s official repository
This downloads Docker’s signing key and registers its package
repository for your Ubuntu release.
apt install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
tee /etc/apt/sources.list.d/docker.sources > /dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
apt update
Install Docker Engine
Install the engine, command-line tools, and the Buildx and Compose plugins.
The service starts automatically on Ubuntu.
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker
Verify the installation
Run a test container. If Docker is working, it prints a short
confirmation message and exits.
docker run --rm hello-world
docker compose version
Run Docker without root
To use Docker as a normal user, add that user to the docker
group. Replace YOUR_USERNAME, then log out and back in
for the change to apply.
usermod -aG docker YOUR_USERNAME
Security note: Membership in the docker
group is equivalent to root access. Add only people you trust with
full control of this VM.
Keep building
Keep Docker and the operating system updated, remove unused images
with docker image prune, and back up your volumes. Note that
ports published by Docker bypass common host firewall rules such as
UFW, so publish only what you need.
References:
Install Docker Engine on Ubuntu
·
Post-installation steps
·
Docker Compose
WP Multisite
Before you begin Working WordPress This guide assumes a working WordPress install on Apache, such as the one from…
Install WordPress on a fresh VM
Before you begin Clean VM Start with a fresh Ubuntu Server LTS virtual machine with root or sudo access…
Install Nextcloud on a fresh VM
Before you begin Docker installed This guide needs Docker Engine and the Compose plugin on an Ubuntu VM. If…
Download Install Docker on a fresh VM
Use the button below to open the download destination.


