Need a step-by-step guide to install or uninstall Docker on Ubuntu? Follow this quick guide and you’ll have Docker installed on your Ubuntu server in just a few steps.
In addition to installing Docker, there is also a section that shows how to completely remove all Docker packages.
How to install Docker and Docker-compose on Ubuntu
Follow the steps below to set up the Docker runtime engine.
- Run the following command against Docker’s official GPG key:
sudo apt-get update sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
- Then run this script to add the repository to your Ubuntu Apt sources (copy and paste into Ubuntu terminal and press Enter).
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
- Finally, install the Docker package and start the daemon by running the two commands below.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo systemctl start docker
To verify that docker is installed and the daemon is running, run the following command:
docker --version sudo docker images docker compose
If these commands display results, you have successfully deployed the Docker runtime engine to your Ubuntu server!
How to completely remove Docker from Ubuntu
- Run this command to get a list of installed Docker packages.
dpkg -l | grep -i docker
This command shows that only the “docker.io” package is installed.
- After identifying the installed Docker packages, run the “apt-get purge” command below to remove them from Ubuntu.
sudo apt-get purge -y docker.io
I only included docker.io because it is the only Docker package installed on my Ubuntu server. Make sure you list all the packages returned in 1 above with a space in between.
The command will pause for 10 seconds after uninstalling Docker, as shown in the screenshot below. Then remove all Docker directories.
However, the /var/lib/docker directory is not deleted.
- To completely remove all Docker directories and subdirectories, run the following command:
sudo rm -rf /var/lib/docker /etc/docker sudo rm /etc/apparmor.d/docker sudo groupdel docker sudo rm -rf /var/run/docker.sock
Frequently Asked Questions
No, Docker is not installed by default on Ubuntu. If you need Docker, you’ll need to install it.
To check if Docker is available on your Ubuntu server, run the “docker –version” command. If the package is available, the command returns the installed version.
If the Docker daemon is stopped, you can start it using the command “sudo systemctl start docker”. This command starts the daemon for the official Docker installation. If the Docker engine is distributed with an unofficial package, use the “dpkg -l | grep -i docker” command.
Then replace “docker” in the previous command with the name returned from the last command.
Run the “sudo systemctl is-active docker” command. If it returns “active”, Docker is running.
a) Use the “docker ps -a” command to get the container ID.
b) Then run the following command to start the Docker container:
docker start container_ID # Replace “container_ID” with the container ID from a).
Installing or uninstalling Docker on Ubuntu is very simple and we hope you found this guide helpful. We’d like to hear from you. Please share your feedback using the comment form at the end of the page.
Or you can ask a question.
Other Useful Resources
- 16.04 – How to completely uninstall Docker – Contact Ubuntu
- Install Docker Engine on Ubuntu | docker documentation
- start daemon | docker documentation