Uncategorized

Install Docker to Ubuntu

I’ve written some articles about LXC in the past, but never anything with a focus on Docker. I use Docker Desktop along with VSCode’s Dev Containers, but that’s the extent of it. I’m using Ubuntu 24.04.4 LTS and I started with an update and upgrade

sudo apt update -y && sudo apt upgrade -y

Remove Docker if Snap-based

Since I’ll be deploying Nextcloud later I don’t want to use Ubuntu’s Snap-based version of Docker

sudo docker info | grep "Docker Root Dir" | grep "/var/snap/docker/" && sudo snap remove docker

Remove Unofficial Docker

Docker documentation recommends removing conflicting docker packages before installing Docker.

sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)

Install Docker

The line to install includes Docker Compose packages which we will be using later.

# Set up Docker's apt respository
# Add Docker's official GPG key:
sudo apt update
sudo apt install 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

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update 

# Install
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Start Docker Automatically

Docker may already be running after install, but let’s enable it with systemd and start it just in case. Docker is dependent on containerd so let’s enable that as well.

sudo systemctl enable --now docker.service
sudo systemctl enable --now containerd.service

Leave a Reply