How to Install or Uninstall Docker on Ubuntu in a Few Easy Steps

Photo of author

By Victor Ashiedu

Published

Do you need a step-by-step guide to install or uninstall Docker on Ubuntu? Join me in this quick guide and you should have Docker installed on your Ubuntu server in a few steps.

How to Install Docker and Docker compose on Ubuntu

Follow the steps below to set up the Docker Runtime Engine.

  1. Run these commands to 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
  1. After that, add the repository to Ubuntu Apt sources by running this script (copy, and paste to your Ubuntu terminal and press the enter key)
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
  1. Finally, install the Docker packages 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 confirm that docker is installed and the daemon is running, run these commands.

docker --version
sudo docker images
docker compose

If these commands display results, you’ve successfully deployed the Docker runtime engine to your Ubuntu server!

How to Completely Uninstall Docker from Ubuntu

  1. Get a list of installed Docker packages by running this command
dpkg -l | grep -i docker

The command shows that I have just the “docker.io” package installed

  1. After identifying the installed Docker packages, remove them from Ubuntu by executing the “apt-get purge” command below:
sudo apt-get purge -y docker.io
I have included just docker.io because that is the only Docker package installed on my Ubuntu server. Ensure you list all the packages returned in 1 above with spaces between them.

As shown in the screenshot below, after uninstalling Docker, the command pauses for 10 seconds. Then, it removes all Docker directories.

However, it does not delete the /var/lib/docker directory.

  1. To completely remove all Docker directories and subdirectories, run this 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

1. Is Docker Installed on Ubuntu by Default?

No, Docker is NOT installed on Ubuntu by default. If you need Docker, you need to install it

2. How Do I know if Docker is Installed on Ubuntu?

To check if Docker is available on your Ubuntu server, run the “docker –version” command. If the package is available, the command returns the version installed.

3. How do I Start Docker in the Ubuntu Terminal?

If the Docker daemon is stopped, you can start it with the “sudo systemctl start docker” command. Note that this command starts the daemon for the official Docker installation. If the Docker engine is deployed with the unofficial packages, get the name the “dpkg -l | grep -i docker” command.

Then, replace “docker” in the previous command with the returned name in the last command.

4. How to Check if Docker is Running?

Run the “sudo systemctl is-active docker” command. If it returns “active” then Docker is running.

5. How to Start a Docker Container?

a) Get the container ID with the “docker ps -a” command.
b) Then, start the Docker container by running the command:

docker start container_ID #replace “container_ID” with the ID of the container from a).

Installing or removing Docker from Ubuntu is pretty straightforward and we hope you found this guide useful. We’re keen to hear from you, so kindly use the comment form at the end of the page to share your feedback.

Alternatively, you can respond to the “Was this page helpful?” question below.

About the Author

Photo of author

Victor Ashiedu

Victor is the founder of InfoPress Media, publishers of Ilifeguides and Itechguides. With 20+ years of experience in IT infrastructure, his expertise spans Windows, Linux, and DevOps. Explore his contributions on Itechguides.com for insightful how-to guides and product reviews.

Related Articles

Get in Touch

We're committed to writing accurate content that informs and educates. To learn more, read our Content Writing Policy, Content Review Policy, Anti-plagiarism Policy, and About Us.

However, if this content does not meet your expectations, kindly reach out to us through one of the following means:

  1. Respond to "Was this page helpful?" above
  2. Leave a comment with the "Leave a Comment" form below
  3. Email us at [email protected] or via the Contact Us page.

Leave a comment