Introduction
Docker is a powerful platform that allows you to automate the deployment of applications inside lightweight containers. This guide will walk you through the installation of Docker on Ubuntu, along with instructions on how to enable, disable, and uninstall it.
Prerequisites
- A computer running Ubuntu (20.04 or later recommended).
- Access to a terminal with sudo privileges.
Step 1: Install Required Packages
Before installing Docker, it’s a good practice to update your system.
Docker requires a few packages to ensure it can be installed correctly.
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
Step 2: Add Docker’s Official GPG Key
To verify the installation, you need to add Docker’s GPG key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 3: Add Docker’s APT Repository
Next, add Docker’s official repository to your system.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Step 4: Update the Package Database Again
After adding the Docker repository, update the package database again to include Docker packages.
sudo apt update
Step 5: Install Docker
Now you can install Docker.
sudo apt install docker-ce -y
Step 6: Start and Enable Docker
sudo systemctl start docker
sudo systemctl enable docker
Step 7: Verify Docker Installation
You can verify that Docker is installed correctly by running:
sudo docker --version
You can also run the hello-world container to test if Docker is working:
sudo docker run hello-world
Step 8: Manage Docker Service
To Stop Docker
If you need to stop the Docker service, use:
sudo systemctl stop docker
To Restart Docker
To restart the Docker service, use:
sudo systemctl restart docker
To Check Docker Status
To check whether Docker is running, use:
sudo systemctl status docker
Optional: Uninstall Docker
If you decide that Docker is not for you, you can uninstall it easily:
Step 1: Remove Docker
sudo apt remove docker-ce -y
Step 2: Remove Docker Dependencies
To remove any unused dependencies, run:
sudo apt autoremove -y
Step 3: (Optional) Remove Docker Images, Containers, and Volumes
If you want to remove Docker images, containers, and volumes, run:
sudo rm -rf /var/lib/docker
Conclusion
You have now installed Docker on Ubuntu and learned how to manage it. Whether you want to run applications in containers or just explore the world of Docker, this guide should help you get started. If you decide to uninstall it, you now know how to do that as well!
Next Steps
Now that you have Docker installed, you can set up a local WordPress development environment using Docker. Check out our next article: Setting Up a Local WP Development Environment with Docker.