How to Install and Use Docker on Linux Servers

Docker packages an application and everything it needs into a container, so it runs the same way on any server. It is a common way to run self-hosted apps on a VPS.

Install Docker

On Debian and Ubuntu, the simplest route is the distribution's package:

sudo apt update
sudo apt install docker.io

On CentOS, AlmaLinux and Fedora, add Docker's own repository (see Docker's install guide for your system), then:

sudo yum install docker-ce

Start it, make it start on boot and check that it is running:

sudo systemctl enable --now docker
sudo systemctl status docker

Run your first container

sudo docker run hello-world
sudo docker run -d --name web -p 8080:80 nginx
sudo docker ps

The second command starts an nginx web server in the background and makes it available on port 8080. Stop and remove it with sudo docker rm -f web.

Everyday commands

  • docker ps -a lists containers; docker images lists downloaded images.
  • docker logs <name> shows a container's output.
  • Build your own image from a Dockerfile with docker build -t myapp ..

Containers use memory, so give a Docker host at least 2 GB of RAM if you plan to run several.

Need a server for this? Cheapest VPS plans with 2 GB RAM or more

In stock when this page loaded. See all 14 matching plans

More RackNerd guides