Dec 02, 2025
Ariffud M.
8min Read
Installing Docker on Ubuntu lets you run containers to build, test, and deploy applications in a clean, consistent environment.
To install Docker on Ubuntu, make sure your system is running a supported version like Ubuntu 22.04 LTS or 24.04 LTS. Then, follow the manual installation steps to set up required packages, add Docker’s official GPG key, and install Docker Engine.
If you’re a Hostinger customer, you can install Docker on your Ubuntu VPS in just a few clicks using our preconfigured template.
Scroll down as we walk you through both methods, share helpful Docker configuration tips after installation, and demonstrate how to troubleshoot common setup issues.
Download free docker cheat sheet
Before installing Docker on Ubuntu, make sure you meet the following prerequisites:
If you prefer a hands-on approach, this section guides you through manually installing Docker on an Ubuntu 24.04 distribution. The same steps apply to other supported Ubuntu versions, such as 22.04.
To start installing Docker, verify that your system is up to date and has all the required packages installed.
ssh username@your_server_ip
sudo apt update && sudo apt upgrade -y
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

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.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

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
sudo apt update
With the necessary repositories set up, you can now proceed to install Docker Engine.
apt-cache policy docker-ce

sudo apt install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable docker
After installing Docker, verify that the installation was successful and Docker is running correctly.
docker --version

sudo systemctl status docker

By default, Docker only lets you run its commands as the root user or with sudo privileges, which can be inconvenient and potentially less secure. If you attempt to run Docker commands as a non-root user, you’ll encounter this error:

However, running Docker without sudo is preferable because it’s faster and improves workflow efficiency. That’s why we suggest creating a dedicated user to run Docker without elevated privileges.
sudo adduser new_user
sudo groupadd docker
sudo usermod -aG docker new_user
su - new_user
groups

docker run hello-world

Congratulations! You’ve successfully set up Docker manually on an Ubuntu VPS using commands.
Using Hostinger’s preconfigured template is the easiest way to install Docker on your Ubuntu VPS. If you choose the Docker VPS hosting plan, the template will be automatically selected, so you can start deploying containerized apps right away.
If you’re a regular VPS hosting customer, don’t worry. You can still install Docker with just a few clicks by selecting the template yourself. Here are the steps:

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

After installing Docker on Ubuntu, take some time to learn the core commands and useful configurations below to get the most out of it.
Start by mastering essential Docker commands to interact with images and containers. This way, you can search and pull prebuilt images like nginx, node, or mysql to quickly launch services without installing anything manually.
docker images
docker search nginx
docker pull nginx
Once you have an image, you can launch and control containers using the following commands. The example below runs a containerized NGINX server on port 8080. This is perfect for testing static websites locally or building reverse proxies for your apps.
docker run -d --name webserver -p 8080:80 nginx
docker start webserver
docker stop webserver
docker ps
You can create your own images using a Dockerfile and share them with others. One use case is to package your Node.js, Python, or Go app into a reusable image and deploy it across different environments or share it with your team.
docker build -t my-app .
docker tag my-app yourusername/my-app:latest
docker push yourusername/my-app:latest
Clean up Docker resources you no longer need to avoid unnecessary disk usage. This helps free up space and reduce clutter from test runs or temporary builds.
docker image prune
docker container prune
docker volume prune docker network prune
Docker Compose lets you define and manage multi-service environments using a single docker-compose.yml file.
version: '3.8'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wp_user
MYSQL_PASSWORD: wp_pass
MYSQL_ROOT_PASSWORD: example
volumes:
- db_data:/var/lib/mysql
web:
image: wordpress
restart: always
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wp_user
WORDPRESS_DB_PASSWORD: wp_pass
depends_on:
- db
volumes:
db_data:docker-compose up -d
Use Docker to avoid polluting your system with multiple language versions or dependencies. This is useful for testing packages, writing scripts, or building apps in an isolated container – all without changing your host setup.
docker run -it --rm node:18 bash
Docker is widely supported in CI tools like GitHub Actions, GitLab CI/CD, and Jenkins. You can containerize your app and run it consistently in development, staging, and production.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: docker build -t my-app .
- run: docker run my-app npm testYou can run full web servers or APIs inside containers to test your apps without deploying them externally. This is ideal for front-end developers who need to serve static assets or test local domains without setting up a full development server.
docker run -d -p 8080:80 httpd
Installing Docker on Ubuntu is usually smooth, but some errors can occur depending on your setup, system configuration, or user permissions. Below are common issues, along with actionable solutions and commands to help you debug quickly.
An error message like “Cannot connect to the Docker daemon” usually indicates that the Docker service isn’t active.
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
If Docker still doesn’t start, check the logs using journalctl:
journalctl -u docker.service
Look for errors such as missing configuration files, port conflicts, or storage driver issues.
If you see “Got permission denied while trying to connect to the Docker daemon socket,” it’s likely a user permission issue.
groups
sudo usermod -aG docker user
Then, log out and back in as that user.
sudo systemctl restart docker
If the problem persists, check out our tutorial on how to fix Docker permission issues.
If you encounter issues with adding the Docker APT repository or installing packages, it might be due to:
Make sure you’ve added the correct repository:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
If apt update fails, check the output for malformed entries or GPG key errors.
If your container starts but doesn’t behave as expected, try the following:
docker logs container_name
docker inspect --format='{{json .State.Health}}' container_namedocker restart container_name
Alternatively, Hostinger VPS users can ask the Kodee AI Assistant to check their container logs. Simply type, “Can you check the logs of the [container_name] container?” like in this example:

Docker uses several ports internally. If you have a firewall enabled, such as Uncomplicated Firewall (UFW), these ports might be blocked.
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
docker run busybox nslookup google.com
If this fails, your container network might be misconfigured.
docker network rm bridge docker network create --driver bridge bridge
You can also ask Kodee to set new firewall rules on your VPS. Simply type, “Set new firewall rules that open port 2375, 2376, 2377, 7946 TCP and 7946, 4789 UDP to any IP address.”
If Docker feels sluggish – for example, if image pulls are slow or containers are lagging – try these steps to troubleshoot the issue.
df -h
docker system df
docker ps -s docker volume ls
If none of the above steps work, try cleaning up unused containers, networks, images, and build cache to improve performance:
docker system prune -a
On some Ubuntu setups, Docker may fail to start containers due to conflicts with security modules, such as AppArmor.
dmesg | grep apparmor
docker run --security-opt apparmor=unconfined your_image
Please note that disabling AppArmor is not recommended in a production environment. If you choose to do so, make sure you’re not unintentionally overriding important kernel security features.
If these errors persist, consider checking your system logs in /var/log/syslog.
Installing Docker on Ubuntu gives you the flexibility to deploy, test, and ship software with fewer headaches, whether you’re running apps locally or managing production workloads.
But installation is just the beginning. To truly benefit from Docker, explore how containers fit into your long-term workflow: