Docker turns "works on my machine" into "works anywhere". Deploying apps with containers on a VPS is far less painful than installing piles of dependencies by hand. This guide takes you from install to your first container.

1. Why Docker

  • Consistent environments: package the app and its dependencies into an image — if it runs locally it runs in production, ending dependency hell.
  • Clean isolation: one container per app, no system pollution, no leftovers when removed.
  • Fast deploys: one command pulls an image and runs common services (databases, blogs, panels).

2. Install Docker

On Ubuntu the easiest path is the official script: curl -fsSL https://get.docker.com | sh. Confirm with docker version. Also install the docker compose plugin for managing multiple containers.

3. Run Your First Container

  • Test: docker run hello-world — a welcome message means it's working.
  • Run Nginx: docker run -d -p 80:80 nginx, then open your IP in a browser.
  • -d runs in the background; -p host:container maps ports.

4. Manage with docker compose

For multiple containers (e.g., site + database), write a compose.yaml: one docker compose up -d starts everything, down stops it, and the config is version-controllable — far cleaner than many run commands.

5. Two Common Pitfalls

  • Data persistence: deleting a container deletes its data — always mount important data to the host with -v volumes.
  • Ports and firewall: after mapping a port you still need to allow it in the VPS/cloud firewall for external access.