How to use Docker

An image of Docker
(Image credit: Future)

Docker has become an essential part of the toolkit for IT teams worldwide. With over 318 billion container image pulls on Docker Hub, it's clear that containerization is here to stay.

This guide walks you through setting up Docker one of the best VPS servers. We'll discuss why this is a good idea, cover the basic steps, explain key concepts, and get you ready to deploy containerized applications.

Get a Hostinger VPS server now

Get a Hostinger VPS server now

Hostinger provide reliable and good value VPS plans for beginners and tech experts alike. Hostinger's hPanel intuitive and easy to use while offering all the tools you need to manage a VPS server.

Should you use Docker?

Docker is an open-source platform that packages applications into containers. Think of containers as lightweight, portable boxes. Each box holds everything your app needs to run: code, libraries, and system tools. Unlike virtual machines, containers share the host system's kernel, making them faster and more efficient.

Docker is ideal for developers, system administrators, and anyone managing web applications. You can run multiple apps on a single server without conflicts. Need WordPress alongside Redis and NGINX? Docker keeps each service isolated yet working together. It's also perfect for testing new software without risking your main system.

There are so many possibilities. You can deploy microservices, set up CI/CD pipelines, or create consistent development environments. Docker ensures your app behaves the same way everywhere. What works on your laptop will work on your VPS.

How to set up Docker on a VPS server

Docker's open-source nature makes it freely available on any Linux or Windows system. But shared hosting limits what you can install. while dedicated servers cost more than most projects need. VPS sits right in the middle with affordable plans, dedicated resources, full root access, and complete control.

Let's talk about how you can install Docker on a standard Linux VPS running cPanel:

  1. Connect to your VPS via SSH using your terminal.
  2. Update system packages: sudo apt-get update.
  3. Install dependencies: sudo apt-get install ca-certificates curl gnupg.
  4. Add Docker's official GPG key for package verification.
  5. Add the Docker repository to your system sources.
  6. Install Docker Engine: sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin.
  7. Verify installation with docker --version or run sudo docker run hello-world.
  8. Optional: Add your user to the docker group using sudo usermod -aG docker $USER.

The basics of using Docker

Before deploying your first container, let's learn some core concepts. Docker has its own vocabulary of terms surrounding various aspects of its containerization technology. Here are the most common ones you might come across.

  • Docker Engine is the core runtime. It builds images, runs containers, and manages everything behind the scenes. This is what you installed in the previous section.
  • Containers are isolated environments where your applications run. Each container includes the app and all its dependencies. Containers start in seconds and use minimal resources.
  • Images are read-only templates for creating containers. Think of an image as a snapshot. You download an image once, then create containers from it whenever needed.
  • Dockerfiles are text files containing build instructions. They define what goes into an image. Each line represents a step: install this package, copy these files, run this command.
  • Docker Compose handles multi-container applications. It uses a YAML file to define services, networks, and volumes. With one command, you can start an entire application stack.
  • Registries store and distribute Docker images. They're like app stores for containers. You can run private registries or use public ones.
  • Docker Hub is the official public registry. It hosts over 8 million container images, including official versions of popular software. Most users pull their base images from here.

Deploying your first container

Now let's deploy your first Docker container. We'll use NGINX as an example.

  1. Pull an image from Docker Hub: docker pull nginx.
  2. Run the container: docker run -d -p 80:80 --name my-web nginx.
  3. Visit your VPS IP address in a browser. You should see the NGINX welcome page.

The -d flag runs containers in the background. The -p flag maps ports between container and host. Here, port 80 inside maps to port 80 on your server. Your container is now deployed and active.

From here, managing containers is straightforward. Here are the essential commands:

  1. List active containers: docker ps.
  2. Stop a container: docker stop my-web.
  3. Remove a stopped container: docker rm my-web.
  4. View downloaded images: docker images.

For multi-container applications, create a docker-compose.yml file defining your services. Then run docker compose up -d to start everything with one command.

If you want to make things even easier, Hostinger provides one-click Docker templates for easy installs on their Ubuntu VPS servers. ScalaHosting, too, offers great managed VPS solutions for Docker with their SPanel control panel.

You're all set!

Great. You now have Docker running on your VPS. But, you won’t see all that it’s capable of until you start experimenting. Here are some things you could try:

  • Deploy a WordPress site with a MySQL database using Docker Compose.
  • Set up a development environment that matches your production server exactly.
  • Run monitoring tools like Grafana and Prometheus to track server performance.
  • Create a reverse proxy with NGINX to manage multiple web applications.
  • Experiment with n8n for workflow automation and connecting different services.
Image

TechRadar Pro created this content as part of a paid partnership with Hostinger. The company had no editorial input in this article, and it was not sent to Hostinger for approval.

Ritoban Mukherjee
Contributing Writer - Software

Ritoban Mukherjee is a tech and innovations journalist from West Bengal, India. These days, most of his work revolves around B2B software, such as AI website builders, VoIP platforms, and CRMs, among other things. He has also been published on Tom's Guide, Creative Bloq, IT Pro, Gizmodo, Quartz, and Mental Floss.