Skip to content

Setting Up Docker on a Linux Server – Launch and Manage Containers on Your Infrastructure

Discover how to install Docker on your Linux server to efficiently run isolated applications and optimize resource usage → Learn more now

12 November 20264 min read42 Views0 helpful

Introduction

Docker is a lightweight, open-source virtualization software that allows you to deploy services or applications isolated on a single system. Unlike traditional virtual machines, it does not emulate or host an additional operating system but only an application environment within the host system. This not only saves resources in general but also ensures low overhead compared to full virtualization. In this guide, we show you how to install Docker on your server.

Preparation

First, you need to connect to your Linux server via SSH. If you need help with this, check out our First Access (SSH) guide. In this tutorial, we use Ubuntu as the Linux distribution.

Installation

Once connected to your Linux server, you can start with the installation methods. Choose the appropriate Linux repository below to see the relevant installation steps.

Ubuntu

First, you need to add and configure the Docker package via apt. This allows you to easily install and update Docker from the repository later.

Run the following commands to add Docker’s official GPG key to your repository list.

Code
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

After that, add the repository to the apt sources with this command:

Code
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Now that you have added the Docker repository, run apt-get update to apply the changes.

Code
sudo apt-get update

Up to this point, you have successfully set up the Docker apt repository. As the final step, install the Docker packages. Install the latest version with this command:

Code
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Debian

First, you need to add and configure the Docker package via apt. This allows you to easily install and update Docker from the repository later.

Run the following commands to add Docker’s official GPG key to your repository list.

Code
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

After that, add the repository to the apt sources with this command:

Code
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Now that you have added the Docker repository, run apt-get update to apply the changes.

Code
sudo apt-get update

Up to this point, you have successfully set up the Docker apt repository. As the final step, install the Docker packages. Install the latest version with this command:

Code
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Fedora

First, you should install the dnf-plugins-core package, which helps manage repositories.

Code
sudo dnf -y install dnf-plugins-core

After the package is installed, add the Docker repository and install Docker with this command:

Code
sudo dnf-3 config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

Docker should now be installed. As the final step, start and enable the service to make it work.

Code
sudo systemctl enable --now docker

To check if the installation was successful, try running the hello-world image with this command:

Code
sudo docker run hello-world

If everything works, you should see a friendly welcome message with some basic info in the terminal. If you get Permission Denied errors, make sure you have enabled Docker compatibility in your web interface and restarted the server as described in the preparation section.

You have successfully installed Docker on your Linux server.

After Installation

Now that Docker is running on your server, you can make a few settings to, for example, avoid using sudo with Docker commands and to start Docker automatically when the server boots.

Use Docker Without Sudo

You can save yourself from always prefixing Docker commands with sudo by creating a new Docker group and adding your user to it. This makes usage more convenient but be aware that you are indirectly granting root privileges.

Create the docker group and add your current user with these commands:

Code
# Create Docker group
sudo groupadd docker

# Add current user to Docker group
sudo usermod -aG docker $USER

We recommend restarting the server afterward so the group membership is reloaded. Alternatively, you can run newgrp docker.

Now test if you can run Docker commands without sudo by running docker run hello-world again.

Tip

Sometimes you get an error due to a configuration file if you ran the command previously with sudo. To fix this, simply delete the Docker directory with rmdir ~/.docker/. It will be recreated automatically on the next command.

If the command runs without errors, you have successfully set up Docker to run without sudo.

Start Docker on System Boot

You can configure Docker to start automatically when the server boots by using systemd – which is used by most Linux distributions.

Tip

On Ubuntu & Debian, Docker is set by default to start automatically on boot. If you use one of these distributions, you don’t need to do anything further.

To enable the Docker service at boot, simply run these commands:

Code
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

To disable the service at boot, replace enable with disable. You can also manage the service with various systemctl commands, for example:

Code
sudo systemctl start [your_service]
sudo systemctl stop [your_service]
sudo systemctl restart [your_service]

Conclusion

Congratulations, you have successfully installed and configured Docker on your Linux server! If you have any questions or problems, our support team is available daily and happy to help!

FAQ

Frequently asked questions

Connect to your server via SSH, add Docker’s official GPG key to your repository list, then set up the Docker repository in your apt sources to install and update Docker from there.
Docker does not emulate or host a separate operating system like a virtual machine but provides only an application environment within the host system, saving resources and reducing overhead compared to full virtualization.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.