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.
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.
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.
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.
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:
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.
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:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
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.
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:
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.
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:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
First, you should install the dnf-plugins-core package, which helps manage repositories.
sudo dnf -y install dnf-plugins-core
After the package is installed, add the Docker repository and install Docker with this command:
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.
sudo systemctl enable --now docker
To check if the installation was successful, try running the hello-world image with this command:
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.
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.
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:
# 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.
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.
You can configure Docker to start automatically when the server boots by using systemd – which is used by most Linux distributions.
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:
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:
sudo systemctl start [your_service]
sudo systemctl stop [your_service]
sudo systemctl restart [your_service]