How to install Docker on Ubuntu? [3 Methods]

How to install Docker on Ubuntu? Get started with Docker on Ubuntu by following our easy-to-follow installation guide. Learn how to install and configure Docker on your Ubuntu system and take advantage of the power of containerization to streamline your development process.

Updated: 01 Nov, 23 by Susith Nonis 11 Min

List of content you will read in this article:

Docker, a powerful containerization platform, has revolutionized the way we develop, package, and deploy applications. If you're an Ubuntu user looking to harness the benefits of Docker, you're in the right place. In this step-by-step guide, we'll walk you through the process of installing Docker on your Ubuntu system.

But first, let's clarify what Docker is and why it's such a game-changer. Docker is an open-source containerization platform that allows you to package your applications and their dependencies into portable containers. These containers can run consistently across various environments, making it easier to develop, test, and deploy software. Whether you're a developer or a system administrator, Docker simplifies the management of applications, ensuring they work flawlessly across different systems. Download the Essential Docker Cheat Sheet Here!

  1. An Ubuntu System: Naturally, you'll need a computer or server running Ubuntu. Docker is compatible with a wide range of Ubuntu versions, so whether you're using the latest release or an older one, you should be good to go.
  2. A User Account with Sudo Privileges: To install Docker, you should have administrative privileges on your Ubuntu system. If you're not logged in as the root user, make sure you have sudo access. This allows you to execute commands with superuser privileges, a necessity for many installation steps.
  3. Terminal or SSH Access: You'll need access to a terminal on your Ubuntu machine or remote access via SSH. This guide will involve running commands in the terminal, so having a basic familiarity with command-line interfaces will be helpful.
  4. A Stable Internet Connection: Docker installation requires downloading packages and dependencies from the internet, so a reliable internet connection is essential. Ensure you're connected before you begin.
  5. Basic Understanding of Packages and Dependencies: While we'll provide step-by-step instructions, having a basic understanding of how packages and dependencies work on Ubuntu will be beneficial. You don't need to be an expert, but some familiarity will help you troubleshoot if needed.

This method is widely recommended because it ensures you get the latest and most up-to-date version of Docker.

Follow these step-by-step instructions to get Docker up and running:

  • Update Package Repository: Open your terminal and make sure your package repository information is up-to-date. Run the following command:

   sudo apt update

   This command fetches the latest information about available packages, ensuring you have access to the most recent Docker packages.

  • Install Prerequisites: Docker requires some additional packages to be installed. You can do this with the following command:

   sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

   These packages are necessary for securely downloading and installing Docker from the repository.

  • Add Docker Repository: Next, add the Docker repository to your system using the following command:

   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

   This command fetches the Docker GPG key and saves it in the appropriate location.

  • Set Up the Stable Repository: Now, set up the stable Docker repository with the following command:

   echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

   This command configures your system to use the stable Docker repository for installation.

  • Install Docker: Finally, it's time to install Docker. Run the following command:

   sudo apt update

   sudo apt install docker-ce docker-ce-cli containerd.io

   This will download and install Docker, along with its command-line interface and container runtime.

  • Start and Enable Docker: To ensure Docker starts automatically on system boot, run these commands:

   sudo systemctl start docker

   sudo systemctl enable docker

This approach involves using the default Ubuntu repositories, which provide a version of Docker that may not be the latest but is still reliable and well-maintained.

Follow these step-by-step instructions to install Docker from the default repositories:

  • Update Package Repository: Open your terminal and ensure your package repository information is up-to-date by running the following command:

   sudo apt update

   This command fetches the latest information about available packages.

  • Install Docker: You can install Docker directly from the default Ubuntu repositories using the following command:

   sudo apt install docker.io

   This command will download and install Docker along with its dependencies.

  • Start and Enable Docker: To ensure Docker starts automatically on system boot, run these commands:

   sudo systemctl start docker

   sudo systemctl enable docker

   Docker is now installed and running on your Ubuntu system.

  • Check Docker Version: You can verify the installation and check the installed Docker version by running:

   docker --version

   This will display the Docker version, confirming that it has been successfully installed.

This method involves using the official Docker installation script, which simplifies the process by handling all the necessary steps automatically.

Follow these step-by-step instructions to install Docker using the installation script:

  • Download the Installation Script: Open your terminal and use the following command to download the Docker installation script:

   curl -fsSL https://get.docker.com -o get-docker.sh

   This command fetches the installation script and saves it as `get-docker.sh` in your current directory.

  • Run the Installation Script: Execute the script using the following command:

   sudo sh get-docker.sh

   This script will automatically detect your Ubuntu version, set up the Docker repository, and install the latest version of Docker.

  • Start and Enable Docker: To ensure Docker starts automatically on system boot, run these commands:

   sudo systemctl start docker

   sudo systemctl enable docker

   Docker is now installed and running on your Ubuntu system.

  • Check Docker Version: Verify the installation and check the installed Docker version by running:

   docker --version

   This will display the Docker version, confirming that it has been successfully installed.

Before you dive into using Docker to manage and deploy applications on your Ubuntu system, it's crucial to verify that the installation was successful. This step ensures that Docker is working correctly and will save you from potential troubleshooting down the line.

Follow these steps to confirm the installation and ensure Docker is functioning as expected:

  • Check Docker Version: Open your terminal and run the following command to check the installed Docker version:

   docker --version

   This command will display the Docker version, confirming that Docker is installed on your system.

  • Test a Hello World Container: Docker provides a simple "Hello World" container that you can use for testing. Run the following command to pull and run this container:

   docker run hello-world

   If Docker is working correctly, you'll see a message indicating that your installation appears to be working. This test ensures that Docker can pull and run containers from the Docker Hub.

  • Check Docker Service Status: To verify that the Docker service is running, use the following command:

   sudo systemctl status docker

   This command will display information about the Docker service, including whether it's active and running.

Tip 1: Updating and Upgrading

Before you install Docker, ensure your system is up-to-date. Run the following commands:

sudo apt update

sudo apt upgrade

This ensures that your Ubuntu system has the latest package information and all available updates, which can prevent potential conflicts during installation.

Tip 2: Cleaning Up Old Docker Versions

If you're upgrading or reinstalling Docker, it's a good practice to remove old versions first. Use the following command to uninstall older Docker versions:

sudo apt-get remove docker docker-engine docker.io containerd runc

Tip 3: Manage Docker as a Non-root User

By default, Docker requires root (sudo) access to run commands. To allow a non-root user to manage Docker, add your user to the `docker` group with this command:

sudo usermod -aG docker $USER

After this, you'll need to log out and log back in for the changes to take effect.

Troubleshooting: Docker Service Not Starting

If the Docker service doesn't start as expected, you can troubleshoot it by checking the service status and examining its logs. Run the following commands:

  • To check the status:

sudo systemctl status docker

  • To view the Docker service logs:

journalctl -xe | grep docker

These commands will provide information about any errors or issues preventing Docker from starting.

Troubleshooting: Docker Installation Script Permission Denied

If you encounter a "Permission Denied" error when trying to run the Docker installation script, ensure you're using the `sudo` command to execute it:

sudo sh get-docker.sh

 

Linux  VPS
Need Affordable VPS Hosting

Starting From $5.99/Monthly

🏅 Fast Delivery
🏅 25+ Data Centers

Congratulations! You've successfully learned how to install Docker on your Ubuntu system using various methods. Docker is a versatile and powerful tool that opens up a world of possibilities for managing and deploying applications. Whether you chose to install it from the official Docker repository, the default Ubuntu repositories, or using the installation script, you're now equipped with the capability to leverage containerization for your projects.

Docker is an open-source containerization platform that simplifies application development, testing, and deployment by packaging applications and their dependencies into portable containers. Installing Docker on your Ubuntu system streamlines the management and deployment of software, making it easier to ensure consistency across different environments.

The best method depends on your preferences and requirements. Using the official Docker repository is recommended for accessing the latest version, while the default repositories provide a reliable option. The installation script offers a quick and automated setup. Choose the one that aligns with your needs and familiarity with the installation process.

Verifying the Docker installation is essential to ensure it's working correctly. It prevents potential issues and ensures that you can confidently use Docker for your projects. By checking the version, testing a container, and verifying the service status, you confirm that Docker is set up as expected.

Docker is compatible with a wide range of Ubuntu versions. Whether you're using the latest release or an older one, you can typically install and use Docker without significant issues. Docker's flexibility makes it a valuable tool for Ubuntu users across various versions.

Yes, you can start using Docker containers right after installation. Once Docker is installed and verified, you have the foundation to begin working with containers. You can pull pre-built images from the Docker Hub or create your custom containers to manage and deploy applications on your Ubuntu system.

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.