What you need before you start
Docker runs on Ubuntu 20.04 LTS, 22.04 LTS, and 24.04 LTS. You will need sudo access (administrator permissions) on your machine, an internet connection to download packages, and about 100 MB of disk space. If you are running Ubuntu in a virtual machine, make sure it has at least 2 GB of RAM allocated.
You have two main paths: install Docker from Ubuntu's default repository, or install it from Docker's own repository. The Docker repository version is newer and receives updates faster, but the Ubuntu repository version is simpler if you want the most stable, tested release for your system.
Key Takeaways
- Docker installs in about five minutes using either the Ubuntu repository or Docker's repository, both reached through the terminal with a few commands.
- After installation, you must add your user to the docker group to run containers without typing sudo every time.
- You can verify the installation worked by running a test container with the command docker run hello-world.
- The Docker repository method gives you newer versions and automatic updates, while the Ubuntu repository method is simpler and more conservative.
Installing from Ubuntu's repository (simpler method)
Open a terminal and update your package list first by running sudo apt update. Then install Docker with sudo apt install docker.io. When prompted, press Y and Enter to confirm. The installation finishes in two to three minutes.
Start the Docker service immediately with sudo systemctl start docker. To make Docker start automatically when your system boots, run sudo systemctl enable docker. You can check that Docker is running by typing sudo systemctl status docker — you should see "active (running)" in the output.
Installing from Docker's repository (newer versions)
This method takes a few more steps but gives you access to the latest Docker releases. First, set up Docker's package repository. Run these commands one at a time:
- sudo apt update
- sudo apt install ca-certificates curl gnupg lsb-release
- sudo mkdir -p /etc/apt/keyrings
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- 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
After those commands finish, update your package list again with sudo apt update, then install Docker with sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. Press Y when prompted. Start the service with sudo systemctl start docker and enable it on boot with sudo systemctl enable docker.
Adding your user to the docker group
By default, you must use sudo to run any Docker command. To avoid typing sudo every time, add your user to the docker group by running sudo usermod -aG docker $USER. Then log out and log back in, or run newgrp docker to activate the group immediately in your current session.
Test that it worked by running docker ps without sudo. If you see a table with column headers (even if it is empty), the group membership is active. If you get a permission error, you may need to restart your system for the change to take full effect.
Verifying Docker works
Run the official test container with docker run hello-world. Docker will download a small test image and run it. If you see a message that says "Hello from Docker!" followed by some explanatory text, the installation is complete and working.
The first time you run this command, it takes 10 to 30 seconds because Docker must download the image. Subsequent runs are instant because the image is already on your machine. If you see an error about not being able to connect to the Docker daemon, restart the Docker service with sudo systemctl restart docker and try again.
Uninstalling Docker if you need to
If you installed from Ubuntu's repository, remove Docker with sudo apt remove docker.io. If you installed from Docker's repository, run sudo apt remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin instead. In either case, this command removes Docker but leaves your images and containers behind.
To also remove all images, containers, and volumes you created, run sudo rm -rf /var/lib/docker. This step is permanent and cannot be undone, so only do it if you are certain you no longer need anything Docker has stored.
Frequently Asked Questions
Which installation method should I choose?
Use Ubuntu's repository if you want the simplest setup and do not mind waiting for updates to reach Ubuntu's maintainers. Use Docker's repository if you want the latest features and security patches immediately. Most people starting out do fine with Ubuntu's repository.
Do I have to add my user to the docker group?
No, but without it you must type sudo before every docker command. Adding your user to the group is a convenience, not a requirement. If you prefer to keep Docker restricted to administrators only, you can skip this step and use sudo every time.
What if I get a "permission denied" error when running docker commands?
You either skipped adding your user to the docker group, or you need to log out and log back in for the group change to take effect. Try running newgrp docker first. If that does not work, log out of your entire session and log back in.
Can I run Docker on Ubuntu 18.04 or older versions?
Docker can run on older Ubuntu versions, but those versions no longer receive security updates. If you are on Ubuntu 18.04 or earlier, consider upgrading to 22.04 LTS or 24.04 LTS first. Both are long-term support releases that receive updates for many years.
How much disk space does Docker need?
Docker itself takes about 100 MB. Each container image you download takes additional space — the hello-world test image is only 13 KB, but real application images typically range from 50 MB to several gigabytes. Plan for at least 10 GB of free space if you plan to work with multiple images.