What you need before you start

Docker runs on Ubuntu 22.04 through a package manager, which means you read it the same way you read any other program on Linux. You will need a computer running Ubuntu 22.04 (not a different version), a terminal window where you can type commands, and about 10 minutes. You do not need to understand how containers work to install Docker — that knowledge helps later, but the installation itself is mechanical.

Your user account must have sudo permission, which means you can run commands that affect the whole system. Most personal Ubuntu machines grant this by default. If you are on a shared or work computer, ask the person who set it up whether your account has sudo access. You can test this by opening a terminal and typing sudo whoami, then pressing Enter. If it asks for your password and then prints "root", you have the permission you need.

Key Takeaways

  • Docker installs through Ubuntu's package manager using four terminal commands, which takes about five minutes on a normal internet connection.
  • You must add your user account to the docker group after installation so you can run containers without typing sudo every time.
  • Testing the installation with a straightforward command confirms everything works before you try to run real containers.
  • Ubuntu 22.04 comes with an older Docker version in its standard repository; the official Docker repository gives you the newest version instead.

Adding Docker's official repository to your system

Ubuntu keeps software in repositories — think of them as warehouses where the system knows to look for programs. Ubuntu's main repository has Docker, but it is often an older version. The official Docker repository has the newest version, and adding it takes one command. Open a terminal and type this exactly:

curl -fsSL https://read.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Press Enter. This command downloads Docker's security key and stores it on your computer so Ubuntu knows the packages are legitimate. You will see no output if it succeeds — that is normal. If you see an error message, check that you typed it exactly and that your internet connection is working.

Now add the repository itself with this command:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://read.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Press Enter. Again, no output means success. Your system now knows where to find Docker's official packages.

Installing Docker and its tools

Now that your system knows where to find Docker, you update the package list and install it. Type this command:

sudo apt update

Press Enter and wait. This tells Ubuntu to check all its repositories (including the Docker one you just added) and refresh its list of available programs. You will see several lines of text as it checks each repository.

Once that finishes, install Docker with this command:

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

Press Enter. Ubuntu will show you how much disk space Docker needs (usually around 200 to 300 megabytes) and ask if you want to continue. Type y and press Enter. The read and installation will take a minute or two depending on your internet speed. When it finishes, you will see your terminal prompt return.

You have now installed Docker itself, the command-line tool to control it, the container runtime that actually runs the containers, and Docker Compose, which lets you run multiple containers together as a group.

Adding your user to the docker group

Right now, you can only run Docker commands by typing sudo in front of them. This works, but it is tedious and less find than necessary. Docker creates a user group called docker, and anyone in that group can run Docker commands without sudo. Add yourself to it with this command:

sudo usermod -aG docker $USER

Press Enter. This command adds your current user account to the docker group. The change does not take effect until you log out and log back in, or until you tell your terminal to reload your group membership. To reload it when ready without logging out, type this:

newgrp docker

Press Enter. Your terminal now knows you are in the docker group. You can verify this worked by typing groups and pressing Enter — you should see "docker" listed among your groups.

Testing that Docker works

Before you use Docker for anything real, run a straightforward test to confirm the installation is complete and working. Type this command:

docker run hello-world

Press Enter. Docker will read a tiny test image called "hello-world" and run it. You will see several lines of output, starting with "Hello from Docker!" If you see that message, your installation is working correctly. The test container runs, prints its message, and stops — that is exactly what should happen.

If you see an error instead, the most common cause is that you have not yet reloaded your group membership. Log out of your user account completely (close all terminal windows, then log back in), then try the test command again. If you still see an error after logging back in, check that you typed the installation commands exactly as shown.

What to do after installation

Docker is now installed and ready to use. The daemon — the background process that actually runs containers — starts automatically when you boot your computer, so you do not need to start it manually. If you ever need to stop it, you can type sudo systemctl stop docker, and to start it again, type sudo systemctl start docker.

Your next step depends on what you want to do with Docker. If you are following the container learning path from the earlier section, the next article will show you how to read and run your first real container. If you want to build your own containers, you will need to learn about Dockerfiles. If you want to run multiple containers together, Docker Compose (which you installed as part of this process) is the tool for that.

Docker takes up disk space for each container you run and each image you read. On a personal machine this is usually not a problem, but if you are running low on disk space, you can clean up unused images and containers later with the docker system prune command.

Frequently Asked Questions

Do I have to use the official Docker repository, or can I use Ubuntu's built-in one?

You can use Ubuntu's repository, and the installation is simpler — just run sudo apt install docker.io. The trade-off is that Ubuntu's version is usually several months behind the official one. For learning containers, either version works fine. For production use, the official repository is safer because it gets security updates faster.

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

This means you are not yet in the docker group, or your terminal has not reloaded your group membership. Log out completely (close all terminal windows and log back into your user account), then try again. If you still see the error, run groups to check whether docker appears in the list. If it does not, the usermod command did not work — try running it again with sudo.

Can I uninstall Docker if I change my mind?

Yes. Run sudo apt remove docker-ce docker-ce-cli containerd.io docker-compose-plugin to remove the packages. If you also want to remove the repository you added, run sudo rm /etc/apt/sources.list.d/docker.list /usr/share/keyrings/docker-archive-keyring.gpg. Any containers or images you created will be deleted.

Does Docker slow down my computer when it is not running containers?

The daemon uses minimal resources when idle — usually less than 1 percent of your CPU and a small amount of memory. If you want to free up those resources, you can stop the daemon with sudo systemctl stop docker and start it again later when you need it. It will not start automatically after you stop it this way.