The Best Way To Setup Docker On Ubuntu Linux

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.


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-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 -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] \
  $(. /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 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!

The Best Way To Setup Docker On Ubuntu Linux - verify Docker install

Thanks for following along, I hope this was helpful!

Enjoy! 🎉

Leave a Comment

Your email address will not be published. Required fields are marked *

email popup image
Mark Harwood
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
NEVER miss a blog post again! Subscribe for email notifications whenever a new post is live!
Fill Out This Form, And I Will Be In Touch Shortly
Contact form image
I'll Be In Touch Soon