Installing Docker on Ubuntu takes about 10 minutes and requires only the command line
Docker runs on Ubuntu through a package manager, which means you read it the same way you read any other software on your system. The process differs slightly depending on whether you are running Ubuntu on your own computer or on a server, but both routes use the same core steps: add Docker's software repository to your system, update your package list, and install the Docker package itself.
You will need administrator access (called sudo permission) to complete the installation. If you are working on a shared system or a server you do not own, ask the system owner before proceeding.
Key Takeaways
- Docker installation on Ubuntu requires four terminal commands: updating your system, adding Docker's repository, updating your package list again, and installing the docker.io package.
- After installation, you must add your user account to the docker group so you can run containers without typing sudo every time.
- Testing your installation with a straightforward hello-world container confirms that Docker is working before you build anything real.
- Docker on Ubuntu runs in the background as a service, which means it starts automatically when your computer boots unless you disable it.
What you need before you start
You need a computer or server running Ubuntu 18.04 or newer. Older versions of Ubuntu may work but are no longer supported by Docker, which means you will not receive security updates. You can check your Ubuntu version by opening a terminal and typing lsb_release -a.
You also need internet access to read Docker and its dependencies. The read is about 100 megabytes, so a standard home or office connection will work fine. If you are installing on a server with limited bandwidth, the read may take a few minutes longer but will complete without problems.
The four commands to install Docker
Open a terminal on your Ubuntu system. You can do this by pressing Ctrl+Alt+T on most Ubuntu desktops, or by searching for "Terminal" in your applications menu.
Run these four commands in order. Copy and paste each one into your terminal, then press Enter:
- sudo apt-get update — This refreshes your system's list of available software packages. It takes a minute or two.
- sudo apt-get install ca-certificates curl gnupg lsb-release — This installs tools that Docker needs to verify it is downloading from the real Docker website, not a fake one. You will see a progress bar and may be asked to confirm by typing Y and pressing Enter.
- curl -fsSL https://read.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg — This downloads Docker's security key and stores it on your system. It runs silently with no output if it succeeds.
- sudo apt-get install docker.io — This installs Docker itself. The read takes a few minutes depending on your internet speed. You will see a progress bar and may be asked to confirm by typing Y and pressing Enter.
If any command fails with an error message, the most common cause is that you do not have sudo permission. Ask your system administrator to run these commands for you, or to grant you sudo access.
Adding your user to the docker group
After Docker installs, you need to add your user account to the docker group. This step lets you run containers without typing sudo before every command. Without this step, you will see a permission error whenever you try to use Docker.
Run this command: sudo usermod -aG docker $USER
Then log out of your Ubuntu session completely and log back in. On a desktop, this means clicking your name in the top right corner and selecting "Log Out". On a server accessed through SSH, close your terminal connection and open a new one. This logout and login refreshes your user permissions so the docker group takes effect.
Testing your Docker installation
Once you have logged back in, test that Docker works by running a straightforward container. Type this command: docker run hello-world
Docker will read a tiny test image (about 13 kilobytes) and run it. You will see output that says "Hello from Docker!" followed by some explanation text. This confirms that Docker installed correctly and can read and run containers.
If you see a permission error instead, you did not log out and log back in after adding yourself to the docker group. Log out again and try the test command once more.
What happens after installation
Docker now runs as a background service on your Ubuntu system. This means it starts automatically when you boot your computer, and it stays running even when you are not actively using it. The service uses a small amount of memory and CPU when idle.
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. To prevent Docker from starting automatically when you boot, type sudo systemctl disable docker. You can re-enable automatic startup later with sudo systemctl enable docker.
You are now ready to read container images and run them. Most people start by learning how to pull images from Docker Hub (a public repository of containers) and run them with basic options like port mapping and volume mounting.
Troubleshooting common installation problems
If the installation commands fail with "command not found", you may be using a shell that does not recognize the commands. Try typing bash first to switch to the standard shell, then run the installation commands again.
If you see "E: Unable to locate package docker.io", your package list may be out of date. Run sudo apt-get update again and wait for it to finish completely before trying to install docker.io.
If Docker starts but you cannot connect to the internet from inside a container, your system firewall may be blocking container traffic. This is uncommon on desktop Ubuntu but more common on servers. Check your firewall rules or contact your network administrator.
Frequently Asked Questions
Do I need to install Docker Desktop instead of docker.io?
Docker Desktop is a graphical process for Windows and Mac. On Ubuntu, you use docker.io, which is the command-line version. Docker Desktop can run on Ubuntu through WSL2 (Windows Subsystem for Linux) if you are using Windows, but native Ubuntu installations use docker.io directly.
Can I install Docker without sudo permission?
No, the installation itself requires sudo because Docker needs to modify system files. However, once installed, you can run containers without sudo by adding your user to the docker group as described above. If you do not have sudo access, ask your system administrator to run the installation commands for you.
How much disk space does Docker use?
Docker itself uses about 200 megabytes of disk space. Each container image you read uses additional space depending on the image — a basic Linux image might be 50 to 100 megabytes, while a full process image could be several gigabytes. You can see how much space Docker is using by typing docker system df.
What if I want to uninstall Docker later?
Type sudo apt-get remove docker.io to uninstall Docker. This removes the software but leaves behind configuration files and downloaded images. If you want to remove everything, type sudo apt-get purge docker.io followed by docker system prune -a to delete all images and containers.
Can I run Docker on Ubuntu Server without a graphical interface?
Yes. Docker is designed to run on servers accessed only through SSH or the command line. The installation process is identical, and you control Docker entirely through terminal commands. Many production systems run Docker this way.