How to Install Docker Engine on Ubuntu

Docker has revolutionized the way developers build, ship, and run applications. By containerizing applications, Docker allows them to run seamlessly across various environments, ensuring consistency and flexibility. In this article, we’ll explore how to install Docker Engine on an Ubuntu system. Whether you’re a beginner or an experienced professional, this tutorial will article you through each step with ease.

How to Install Docker Engine on Ubuntu

What is Docker Engine?

Docker Engine is the core of Docker, enabling containerized application development. It’s a containerization technology that runs containers on a host machine. Docker Engine consists of three components:

  1. Server: A daemon process that manages Docker containers.
  2. REST API: Used to interact with the Docker daemon programmatically.
  3. CLI (Command-Line Interface): Enables users to communicate with Docker using commands.

By installing Docker Engine, developers can streamline their workflows, deploy applications quickly, and optimize resource usage.

Prerequisites for Installing Docker Engine

Before installing Docker Engine on Ubuntu, ensure that the following prerequisites are met:

  1. Ubuntu Version: Docker supports Ubuntu versions 22.04, 20.04, and 18.04. Ensure your system is running a compatible version.
  2. User Privileges: You need a user account with sudo privileges to perform administrative tasks.
  3. Internet Access: Installation requires downloading packages from Docker's repositories.

Step 1. Update the System

The first step involves updating the system’s index to ensure all packages and dependencies are current. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

The apt update command refreshes the list of available packages, while apt upgrade installing the latest updates for installed software. Reboot your system if necessary after completing the update.

Step 2. Uninstall Older Docker Versions

If you have older Docker packages, such as docker, docker.io, or docker-engine, they should be removed before installing the latest version. Run the following command to uninstall older versions:

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

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

This step ensures that outdated packages won’t conflict with the new installation. Rest assured, existing images and containers won’t be removed during this process.

Step 3. Install Required Dependencies

Docker relies on specific packages to function correctly. Install these dependencies using the command below:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
  • apt-transport-https: Ensures secure package downloads.
  • ca-certificates: Verifies SSL certificates.
  • curl: Used to download files and interact with APIs.
  • software-properties-common: Adds the ability to manage software repositories.

Step 4. Add Docker’s Official GPG Key

To ensure the authenticity of Docker packages, add Docker’s GPG (GNU Privacy Guard) key to your system:

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

This command retrieves Docker’s GPG key and saves it as a keyring file on your system.

Step 5. Add Docker’s Repository

Once the GPG key is added, include Docker’s official repository in your system’s package source list. Use the following command:

echo "deb [arch=$(dpkg --print-architecture) 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

Here’s what this command does:

  • Adds the repository for your system’s architecture.
  • Uses the lsb_release -cs command to identify your Ubuntu version.
  • Ensures the repository is added securely.

Step 6. Update the Package Index Again

After adding Docker’s repository, update the package index to include Docker packages:

sudo apt update

If the repository was added correctly, Docker packages will now be available in your system’s package list.

Step 7. Install Docker Engine

With the repository configured, install Docker Engine using the command: 

sudo apt install -y docker-ce docker-ce-cli containerd.io
  • docker-ce: The Docker Engine Community Edition package.
  • docker-ce-cli: Docker’s Command-Line Interface.
  • containerd.io: A high-performance container runtime.

The -y flag automatically confirms the installation process, so you won’t need to approve prompts manually.

Step 8. Verify the Docker Installation

Once Docker is installed, confirm that it’s working by checking its version: 

docker version

The output should display the installed Docker version, indicating a successful installation.

Verify the Docker Installation- Docker Version

You can also test Docker by running the hello-world container: 

sudo docker pull hello-world
sudo docker run hello-world

This command downloads and runs a test container, displaying a message if everything is configured correctly.

Docker Hello World container

Step 9. Manage Docker as a Non-Root User

By default, Docker commands require sudo. To allow non-root users to run Docker commands, add your user to the docker group: 

sudo usermod -aG docker $USER

After running this command, log out and back in to apply the changes. Alternatively, use newgrp docker to refresh the session without logging out.

Step 10. Enable and Start Docker Service

To ensure Docker starts automatically upon boot, enable the service with the following commands: 

sudo systemctl enable docker sudo systemctl start docker

The systemctl enable command configures Docker to start at boot, while systemctl start starts the service immediately.

Troubleshooting Common Issues

If you encounter issues during the installation process, consider the following solutions:

  1. Docker Service Not Starting: Check the status using sudo systemctl status docker. Review the error logs for insights.
  2. Permission Errors: Ensure your user is part of the docker group.
  3. Network Connectivity Issues: Verify your internet connection and check firewall settings.

Conclusion

Installing Docker Engine on Ubuntu is a straightforward process that involves updating your system, configuring repositories, and running installation commands. Once installed, Docker opens up a world of possibilities for application development and deployment. Following this article, you’ve set up a powerful tool to simplify your workflows and enhance your development environment.

Now that Docker is installed, you can start building and managing containers. Explore Docker Hub for prebuilt images, experiment with Docker Compose for multi-container applications, and take your projects to the next level. Docker’s versatility ensures it will be a valuable addition to your software toolkit.

Automate Docker installation on Ubuntu with ease! Use my script: Install.sh ๐Ÿณ or you can download the source codeโ€‹โ€‹โ€‹โ€‹! ๐Ÿš€


Similar Articles
Ezmata Technologies Pvt Ltd
You manage your core business, while we manage your Infrastructure through ITaaS.