As someone that’s created a lot of Docker instances on Linux, the method is now second nature to me. But at one time I had no idea on the best way to setup Docker on Ubuntu Linux.
I tried a ton of methods and tutorials, with all of them missing something. This often lead to installs not working quite right or being hard to scale.
I wanted to share with you my method for installing Docker on Ubuntu Linux. I’ve also written this on Medium in case you prefer reading over there.
How to Optimise MySQL 8.4 on Windows
5 months since my last post! That’s what having a full-time job and a third…
How to Upgrade MySQL Community to MySQL Enterprise on Red Hat 9
Been a while since I made a post, so let’s jump straight back in with…
How to Setup WordPress Backups (FREE!)
Personally, I like my website. A lot. And I wouldn’t want one mistake to make…
Install NGINX on an Offline RHEL System – 2 Systems Required!
Been a while since my previous post, but let’s hope the magic hasn’t rubbed off…
MySQL 8.4 Replication with SSL on Ubuntu 22.02
So I recently wrote a post and made a YouTube video on setting up MySQL…
Gutenberg Just Broke my Website
More of a story and vent than an informative article. So to save you reading…
Introduction
So as an overview, I will be using Ubuntu 22.04 but you can use the latest 24.04 if you like. The general flow of this setup will be to update Linux and create the directories that are needed. Once that’s done, we can set the permissions and start adding docker to our apt-get repository.
Lets jump in now!
The Best Way To Setup Docker On Ubuntu Linux
First things first, is to update your Ubuntu machine. You could skip this step is are sticking to a particular release, but I always take the opportunity out of best practice.
Update Ubuntu
To update Ubuntu, run the below commands:
sudo do-release-upgrade
sudo apt-get update; sudo apt-get upgrade
You might also be prompted on either of those commands, just press ‘Y’ and then click enter.
Creating Directories
We now need to create the directories needed for Docker. Follow the commands below to complete this:
note that a new directory will need to be created for every image you want to run in Docker
sudo mkdir -p /home/docker
sudo mkdir -p /home/docker/image (e.g. traefik)
Install Docker
Now onto the meat and potatoes! Run the following commands to install Docker:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudo apt-get update
sudo apt-get 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
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
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
I know that’s quite a lot just to install Docker, but this does a bunch of helpful stuff too. For one, it adds Docker into the apt repository, which enabled apt to install the latest stable version of Docker.
Verify Docker Install
Finally, now that you’ve installed Docker using the commands above we can check it’s working.
Thankfully, Docker includes a simple way to do this. Use the command below:
sudo docker run hello-world
And as long as you get an output similar to the below screenshot, you’re all good!

Thanks for following along, I hope this was helpful!
Enjoy! 🎉