How to Install Docker and Run Your First Container on a VPS

How to Install Docker and Run Your First Container on a VPS

Docker makes it easy to run and manage isolated applications on any system. Whether you're hosting a game server, control panel, or backend service, Docker can simplify deployment dramatically. In this guide, we’ll walk you through installing Docker on a Ubuntu VPS and running your first container.


Why Use Docker on a VPS?

  • Isolation: Containers run separately from the host system.
  • Portability: Move containers between machines easily.
  • Reproducibility: Run the same environment every time.
  • Speed: Lightweight compared to full VMs.

Perfect for game server tools, control panels, or microservices.


Step 1: Update Your VPS

Make sure your VPS is up to date:

sudo apt update && sudo apt upgrade -y

Step 2: Install Docker

Run the following commands:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

To verify Docker installed correctly:

docker --version

You should see something like:

Docker version 24.0.5, build ced0996

Step 3: Add Your User to the Docker Group

This allows you to run Docker without sudo every time.

sudo usermod -aG docker $USER

Log out and back in for the change to apply, or run:

newgrp docker

Step 4: Run Your First Container

Let’s try something simple:

docker run hello-world

Docker will download a test image and output a success message if everything works.


Step 5: Run a Web Server Container (Optional)

As a real example, let’s run NGINX on port 80:

docker run -d -p 80:80 --name webserver nginx

You can now visit your VPS IP in a browser and see the default NGINX page.


Step 6: View Running Containers

docker ps

To stop your container:

docker stop webserver

To remove it:

docker rm webserver

Summary

You’ve now got Docker installed and running on your VPS, along with your first container. This sets the stage for more complex services, including game panels, monitoring tools, databases, and beyond.