What you need to do before you start

Docker runs on Ubuntu 22.04 through the official Docker repository, which gives you the newest version and automatic updates. You will need a user account with sudo access (the ability to run commands as the system administrator), an internet connection, and about 10 minutes. The process removes any old Docker versions first, then installs the current one from Docker's own repository instead of Ubuntu's default software sources.

Before you begin, open a terminal window. You can do this by pressing Ctrl+Alt+T, or by clicking the Activities button in the top left, typing "terminal", and pressing Enter. All the commands below go into this terminal window, one at a time. When you see a line that starts with a dollar sign ($), type everything after the dollar sign and press Enter.

Key Takeaways

  • Docker installs from Docker's official repository, not Ubuntu's default software sources, so you must add the repository before installation.
  • The installation removes any old Docker versions automatically and takes about five minutes on a typical internet connection.
  • After installation, you must add your user to the docker group so you can run Docker commands without typing sudo every time.
  • Testing the installation with a simple command confirms Docker is working before you start using it for real work.

Remove old Docker versions and update your package list

Start by removing any Docker installation that might already be on your system. Type this command:

sudo apt-get remove docker docker-engine docker.io containerd runc

If Docker is not installed, you will see a message saying the packages were not found. That is fine — the command still succeeds. Next, update your package list so Ubuntu knows where to find the newest software:

sudo apt-get update

This command contacts Ubuntu's software repositories and downloads a list of what is available. It takes a minute or two depending on your internet speed. You will see lines of text scrolling past as it works. When it finishes and you see the command prompt again, move to the next step.

Install the tools Docker needs to run

Docker requires a few supporting programs to work correctly. Install them with this command:

sudo apt-get install ca-certificates curl gnupg lsb-release

Ubuntu will ask you to confirm by typing Y and pressing Enter. These four packages let your computer verify that Docker's repository is real (ca-certificates), download files from the internet (curl), check that software is authentic (gnupg), and identify which version of Ubuntu you are running (lsb-release). The installation takes less than a minute.

Add Docker's official repository to your system

Now you will tell Ubuntu where to find Docker's official software. First, download Docker's security key, which proves that the software you download is genuine:

sudo mkdir -p /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

The first command creates a folder where Ubuntu stores security keys. The second command downloads Docker's key and saves it. Both commands run silently if they succeed — you will just see the command prompt appear again.

Next, add Docker's repository itself:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

This long command tells Ubuntu that Docker's official repository exists and where to find it. Copy it exactly as written. When it finishes, update your package list again so Ubuntu knows about Docker's software:

sudo apt-get update

Install Docker and start it running

Now install Docker itself:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Ubuntu will ask for confirmation. Type Y and press Enter. This installs four things: docker-ce (the main Docker program), docker-ce-cli (the command-line tool you use to control Docker), containerd.io (the system that actually runs containers), and docker-compose-plugin (a tool for running multiple containers together). The download and installation takes two to five minutes depending on your internet speed.

When it finishes, Docker is installed but not yet running. Start it with this command:

sudo systemctl start docker

This command tells Ubuntu to start the Docker service. You will not see any output — just the command prompt. Docker is now running in the background.

Add your user to the docker group so you do not need sudo

Right now, you must type sudo before every Docker command. To avoid this, add your user account to the docker group:

sudo usermod -aG docker $USER

This command adds your current user to the docker group, which has permission to run Docker without sudo. The change takes effect the next time you log in. For it to take effect right now without logging out, type:

newgrp docker

This activates the group change in your current terminal session. You can now run Docker commands without sudo.

Test that Docker is working

Verify the installation by running Docker's test image:

docker run hello-world

Docker will download a small test image and run it. You should see output that says "Hello from Docker!" followed by some explanation of what just happened. This confirms that Docker is installed correctly and can download and run containers.

If you see an error instead, the most common cause is that the group change has not taken effect yet. Log out completely (close all terminal windows and your user session) and log back in, then try the command again.

Make Docker start automatically when your computer boots

By default, Docker starts manually. If you want it to start automatically every time your computer boots, type:

sudo systemctl enable docker

This tells Ubuntu to start Docker automatically in the background whenever the system starts. You can verify it is set to start automatically by typing:

sudo systemctl is-enabled docker

If the output says "enabled", Docker will start on boot. If it says "disabled", Docker will only run when you start it manually with the command from the previous section.

Frequently Asked Questions

What if I get a "permission denied" error when I run docker commands?

This means the group change has not taken effect yet. Log out completely by closing your terminal and clicking your username in the top right, then selecting "Log Out". Log back in and open a new terminal. The docker commands should work without sudo now.

Can I install Docker on a system without sudo access?

No. Docker requires root-level permissions to run containers, so you must have a sudo account. If you do not have sudo access, ask your system administrator to either give you sudo access or install Docker for you.

Do I need to do anything special if I am running Ubuntu in a virtual machine?

Docker will work in a virtual machine, but the virtual machine itself must have virtualization enabled in its settings. If Docker installation succeeds but containers will not run, check your virtual machine's CPU settings to ensure nested virtualization is turned on.

What is the difference between docker-ce and docker-ee?

Docker-ce is the free Community Edition, which is what most people use. Docker-ee is the paid Enterprise Edition with additional support and security features. This guide installs docker-ce, which is sufficient for learning and most personal projects.

Will Docker slow down my computer when it is not in use?

Docker uses minimal resources when no containers are running. The Docker daemon (the background service) uses only a small amount of memory. If you want to stop Docker from running in the background, type sudo systemctl stop docker. To start it again, type sudo systemctl start docker.