Back to blog

Easily Install Docker on Linux VPS

Admin
Easily Install Docker on Linux VPS

Docker is a popular platform that allows you to develop, ship, and run applications in containers. Installing Docker on a Linux VPS is a relatively simple and straightforward process, especially if you follow the appropriate steps. This article will guide you through the necessary steps to install Docker on your server.

Prerequisites

Before you begin the installation of Docker, ensure that your VPS meets the following requirements:

  • A supported Linux distribution (Ubuntu, Debian, CentOS, etc.)
  • Root access or sudo privileges
  • An active Internet connection

Installing Docker on Ubuntu

Ubuntu is one of the most popular Linux distributions for running Docker. Here’s how to install it:

Updating the System

Before installing Docker, it’s wise to update your system:

sudo apt update && sudo apt upgrade -y

Installing Dependencies

Install the necessary packages to allow apt to use repositories over HTTPS:

sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

Adding Docker's GPG Key

Add Docker's official GPG key to ensure the authenticity of the packages:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Adding the Docker Repository

Next, add the Docker repository to your sources list:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Installing Docker

After adding the repository, update the package database and install Docker:

sudo apt update && sudo apt install docker-ce -y

Verifying the Installation

To verify that Docker is installed correctly, run the following command:

sudo systemctl status docker

You should see a message indicating that the Docker service is active.

Installing Docker on CentOS

If you are using CentOS, follow these steps to install Docker:

Updating the System

Start by updating your system:

sudo yum update -y

Installing Dependencies

Install the necessary tools:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Adding the Docker Repository

Add the Docker repository to your system:

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Installing Docker

Install Docker with the following command:

sudo yum install docker-ce -y

Verifying the Installation

Check that Docker is working correctly:

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker

Configuring Docker

After installation, you can configure Docker according to your needs. Here are some common configurations:

Adding Your User to the Docker Group

To avoid using sudo every time you run a Docker command, add your user to the Docker group:

sudo usermod -aG docker $USER

Log out and log back in for the changes to take effect.

Configuring the Docker Daemon File

The Docker configuration file is usually located at /etc/docker/daemon.json. You can modify it to change certain settings:

{
  "registry-mirrors": ["https://your-mirror-url"]
}

After making changes, restart Docker:

sudo systemctl restart docker

Running Your First Docker Container

To test that everything is working correctly, try running your first container:

docker run hello-world

This command will download a test image and run a container that displays a welcome message.

Troubleshooting

If you encounter issues while installing or running Docker, here are some troubleshooting tips:

  • Check Docker logs: You can view the logs for more information on errors using the command sudo journalctl -u docker.
  • Check dependencies: Ensure that all required dependencies are installed.
  • Restart the service: If Docker is not functioning as expected, try restarting the service with sudo systemctl restart docker.

Conclusion

Installing Docker on a Linux VPS is a straightforward process that allows you to start developing and deploying your applications quickly. Whether you are using Ubuntu, CentOS, or another distribution, the steps outlined above will guide you through the installation and configuration process. Once Docker is installed, you can explore a world of possibilities in containerization.