How to install Docker on Ubuntu (manual installation and VPS template)

Docker is a powerful platform to automate application deployments using lightweight, portable containers. Setting up Docker on a Linux server can significantly enhance your development workflow.

In this guide, you’ll learn how to install Docker on Ubuntu using Hostinger’s VPS template and manually. By the end of this article, you’ll have a fully functional Docker setup ready for your projects.

Download free docker cheat sheet

Prerequisites before installing Docker on Ubuntu

Before following our Docker installation guide, make sure your Ubuntu system meets the following prerequisites:

  • Supported Ubuntu version. Use a long-term support (LTS) version of Ubuntu, such as Ubuntu 20.04, 22.04, or 24.04.
  • Server requirements. Verify that your VPS meets the minimum requirements for Docker. Your system should have a 64-bit architecture and at least 2 GB of RAM.
  • Basic Linux knowledge. Familiarity with basic Linux commands is beneficial for installing and managing Docker applications.

Suggested Reading

Need a refresher on what Docker is? Check out our article to understand how Docker works and what its components are.

How to install Docker manually

For those who prefer a hands-on approach, this section will guide you through manually installing Docker on an Ubuntu 24.04 distribution.

1. Install necessary packages

To begin installing Docker, verify that your system is up to date and has all the required packages installed. Follow these steps:

  1. Open your terminal and connect to your VPS using SSH. Replace username and your_server_ip with your actual credentials:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ssh username@your_server_ip
ssh username@your_server_ip
ssh username@your_server_ip
  1. Update your package list to ensure your server uses the newest versions of packages and their dependencies:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apt update && sudo apt upgrade -y
sudo apt update && sudo apt upgrade -y
sudo apt update && sudo apt upgrade -y
  1. Install the necessary packages to allow apt to use repositories over HTTPS:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

2. Add Docker’s official GPG key

To ensure the authenticity and security of the Docker packages, you need to add Docker’s official GPG key and set up the Docker repository. Here’s the guide:

  1. Run the following curl command to add Docker’s GPG key:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. Add the official Docker repository to your APT sources:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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
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
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
  1. Update your package list to include packages from the new repository:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apt update
sudo apt update
sudo apt update

3. Install Docker

With the necessary repositories set up, you can now proceed to install Docker. Here are the steps to do so:

  1. Make sure you’re about to install Docker from its official repository instead of the default Ubuntu repository:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt-cache policy docker-ce
apt-cache policy docker-ce
apt-cache policy docker-ce
  1. You’ll see the following output, indicating that Docker will be installed from the correct repository:
  1. Execute this command to install Docker Engine, Docker Community Edition, and containerd runtime, all necessary for running Docker containers:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apt install docker-ce docker-ce-cli containerd.io -y
sudo apt install docker-ce docker-ce-cli containerd.io -y
sudo apt install docker-ce docker-ce-cli containerd.io -y
  1. Ensure Docker starts automatically when your system boots:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo systemctl enable docker
sudo systemctl enable docker
sudo systemctl enable docker

4. Verify Docker installation

After installing Docker, it’s important to verify that the installation was successful and that Docker is running correctly. Here are the instructions:

  1. Confirm the Docker version installed on your system:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker --version
docker --version
docker --version
  1. Here’s the expected output:
  1. Use the following command to check the Docker service’s status:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo systemctl status docker
sudo systemctl status docker
sudo systemctl status docker
  1. You should see an output indicating that Docker is active and running:
  1. To exit from this status screen, press Q on your keyboard.

5. Run Docker without sudo (optional)

By default, Docker only allows you to run its commands as a root user with sudo privileges, which can be inconvenient and potentially less secure. If you attempt to run Docker commands as a non-root user, you might see an error like this:

However, running Docker without sudo is more advisable because it’s quicker and simpler. Follow this guide:

  1. Add a new user if you don’t have one. Here, we name it new_user:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo adduser new_user
sudo adduser new_user
sudo adduser new_user
  1. You’ll be prompted to set up a new password for this user.
  2. Run the following command to create the docker group:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo groupadd docker
sudo groupadd docker
sudo groupadd docker
  1. Add new_user to the docker group:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo usermod -aG docker new_user
sudo usermod -aG docker new_user
sudo usermod -aG docker new_user
  1. Switch to the recently created user:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
su - new_user
su - new_user
su - new_user
  1. Verify that this user is part of the docker group:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
groups
groups
groups
  1. Here’s the output:
  1. Run a simple Docker command to verify that you can run commands without sudo:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run hello-world
docker run hello-world
docker run hello-world
  1. You should see an output showing that Docker is running correctly as a non-root user:

Congratulations! You’ve successfully set up Docker manually on an Ubuntu VPS using commands.

How to install Docker on Ubuntu using Hostinger’s VPS template

Using Hostinger’s preconfigured template is the easiest way to set up Docker on your Ubuntu VPS. Available for both VPS and Docker hosting plans, this method saves time and ensures Docker is installed correctly with all necessary components.

Follow these steps to install Docker with Hostinger’s VPS template:

  1. Log in to hPanel and navigate to VPS → Manage next to your server.
  2. From the VPS dashboard, go to OS & Panel → Operating System in the left sidebar.
  1. On the Operating System page, select Application → Docker.
  1. Click the Change OS button and wait for the installation process to finish, which typically takes about 10 minutes.

That’s it! You have installed Docker on your VPS and are ready to deploy applications.

What are some Docker configuration tips?

After installing Docker, new users should become familiar with several necessary commands and tasks. This section will cover some Docker post-installation configurations and tips.

Basic Docker commands

Getting started with Docker involves learning a few essential commands. Here are some commands that every new user should know:

  • List Docker images:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker images
docker images
docker images
  • Search for images on Docker Hub:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker search image_name
docker search image_name
docker search image_name
  • Download a Docker image from Docker Hub:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker pull image_name
docker pull image_name
docker pull image_name

Furthermore, check our Docker cheat sheet guide to learn all the most essential commands and their purposes.

Running and managing Docker containers

Running and managing containers is a core part of working with Docker. Here’s a guide to perform these tasks:

  • Run a Docker container using the specified image:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker run -d --name container_name image_name
docker run -d --name container_name image_name
docker run -d --name container_name image_name
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker start container_id_or_name
docker start container_id_or_name
docker start container_id_or_name
  • Stop a running container:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker stop container_id_or_name
docker stop container_id_or_name
docker stop container_id_or_name
  • List all running containers:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker ps
docker ps
docker ps

Working with Docker images

Docker images are the basis for containers. Here’s how you can work with images:

  • Build a Docker image from a Dockerfile in the current directory:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker build -t image_name .
docker build -t image_name .
docker build -t image_name .
  • Tag an image with a specific name and tag:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker tag source_image_name target_image_name:tag
docker tag source_image_name target_image_name:tag
docker tag source_image_name target_image_name:tag
  • Log in to Docker Hub, tag your image, and push it to your repository:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker login
docker tag image_name dockerhub_username/image_name:tag
docker push dockerhub_username/image_name:tag
docker login docker tag image_name dockerhub_username/image_name:tag docker push dockerhub_username/image_name:tag
docker login
docker tag image_name dockerhub_username/image_name:tag
docker push dockerhub_username/image_name:tag

Deleting unused Docker components

To keep your environment clean and efficient, you need to remove unused Docker components regularly. Here’s how to do so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker image prune
docker image prune
docker image prune
  • Delete all stopped containers:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker container prune
docker container prune
docker container prune
  • Clean unused Docker volumes:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker volume prune
docker volume prune
docker volume prune
  • Erase all unused networks:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker network prune
docker network prune
docker network prune

Using Docker Compose

Docker Compose is a powerful tool for managing multi-container applications. Here’s a basic command to get it started:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker-compose up -d
docker-compose up -d
docker-compose up -d

This starts services defined in the docker-compose.yml file in detached mode.

Suggested Reading

Did you know that you can run WordPress as a Docker container? Learn how in our article.

Troubleshooting common Docker installation issues

Installing Docker can sometimes come with challenges. Here are some common issues and actionable tips to resolve them.

Docker daemon not running

If you receive an error message indicating that the Docker daemon is not running, it likely means the service is not active. To resolve this, start the Docker service using the command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo systemctl start docker
sudo systemctl start docker
sudo systemctl start docker

You can verify the Docker daemon’s status by running:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo systemctl status docker
sudo systemctl status docker
sudo systemctl status docker

Can’t connect to the Docker daemon

If you encounter the “Cannot connect to the Docker daemon at unix:///var/run/docker.sock” error, it usually means the Docker service is not running or there are permission issues.

First, make sure the Docker service is running with:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo systemctl start docker
sudo systemctl start docker
sudo systemctl start docker

Then, verify that your user is part of the Docker group by running the following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
groups
groups
groups

To solve permission denied issues, follow our detailed tutorial.

Installation issues from repositories

Problems when adding the Docker APT repository or during package installation can arise from incorrect repository setup. Make sure you have added the official repository and updated your package list by running:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apt update
sudo apt update
sudo apt update

Running containers not responding

If running containers are not responding or behaving unexpectedly, check the container logs to diagnose the issue. Use the command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker logs container_id
docker logs container_id
docker logs container_id

Alternatively, Hostinger VPS users can use the Kodee AI Assistant to check their container logs. Simply ask, “Can you check the logs of the [container_name] container?” like the following example:

If necessary, restart the container by executing:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
docker restart container_id
docker restart container_id
docker restart container_id

Firewall and network configuration issues

Sometimes, Docker might face issues due to firewall settings or network configurations blocking necessary ports. Ensure that your firewall allows traffic on Docker’s default ports. You can check your firewall rules and add necessary exceptions if required.

For example, if you’re using Uncomplicated Firewall (UFW), you can allow Docker traffic with:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo ufw allow 2375/tcp
sudo ufw allow 2376/tcp
sudo ufw allow 2377/tcp
sudo ufw allow 7946/tcp
sudo ufw allow 7946/udp
sudo ufw allow 4789/udp
sudo ufw allow 2375/tcp sudo ufw allow 2376/tcp sudo ufw allow 2377/tcp sudo ufw allow 7946/tcp sudo ufw allow 7946/udp sudo ufw allow 4789/udp
sudo ufw allow 2375/tcp
sudo ufw allow 2376/tcp
sudo ufw allow 2377/tcp
sudo ufw allow 7946/tcp
sudo ufw allow 7946/udp
sudo ufw allow 4789/udp

Additionally, verify your network settings to ensure Docker can communicate with external servers to download images and perform other tasks.

Managing firewall with kodee

You can also ask Kodee to set new firewall rules on your server. To do this, simply ask, “Set new firewall rules that open port 2375, 2376, 2377, 7946 TCP and 7946, 4789 UDP to any IP address.”

Conclusion

In this Docker tutorial, you’ve learned how to install Docker on an Ubuntu system, both using Hostinger’s VPS template and a manual approach. You’ve also understood the importance of verifying the installation and troubleshooting common issues.

Furthermore, it’s advisable to practice essential Docker commands, manage containers and images, and clean up unused components. By following these instructions, you can effectively set up and manage Docker for deploying your applications.

How to install Docker on Ubuntu FAQ

Are there any specific configurations needed after installing Docker on Ubuntu?

After installing Docker on Ubuntu, it’s recommended to configure Docker to run without sudo for convenience. Additionally, make sure your firewall settings allow Docker traffic and adjust any necessary network configurations for smooth access to external resources.

Can I install Docker on any version of Ubuntu?

Currently, Docker supports installation on Ubuntu 20.04, 22.04, and 24.04. It’s advisable to use a long-term support version for stability. Additionally, always check Docker’s official documentation for the latest compatibility information.

All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.

Author
The author

Ariffud Muhammad

Ariffud is a Technical Content Writer with an educational background in Informatics. He has extensive expertise in Linux and VPS, authoring over 200 articles on server management and web development. Follow him on LinkedIn.