What I Wanted to Do
I had a VPS (Ubuntu 22.04) and wanted to run my app in Docker on it — the same way I develop locally.
Environment
- Ubuntu 22.04 LTS (VPS)
- Docker + Docker Compose
Steps
1. Connect to the VPS via SSH
ssh root@YOUR_VPS_IP
2. Update the System
apt update && apt upgrade -y
3. Install Docker
curl -fsSL https://get.docker.com | sh
4. Verify the Installation
docker --version
docker run hello-world
5. Install Docker Compose
apt install docker-compose-plugin -y
docker compose version
6. Allow a Non-root User to Run Docker
usermod -aG docker YOUR_USERNAME
Log out and back in for the change to take effect.
Security Settings
Disable Root SSH Login
nano /etc/ssh/sshd_config
# Change: PermitRootLogin no
systemctl restart sshd
Set Up the Firewall
ufw allow 22/tcp # SSH
ufw allow 80/tcp # HTTP
ufw allow 443/tcp # HTTPS
ufw enable
Common Pitfalls
curl | shinstalls the latest stable Docker version automatically- Running Docker as root is a security risk — always create a non-root user
- UFW and Docker can conflict; Docker may bypass UFW rules on some setups
For creating a non-root user, see Manage Linux Users (useradd/userdel).
Related Posts
- Install Docker on Windows
- Docker Compose Basics
- Docker Basic Commands (run/stop/rm/ps)
- How to Fix “Permission Denied” on Linux
Recommended Cloud Hosting
Looking for reliable cloud infrastructure? Check out these developer-friendly services.
- Cherry Servers - High-performance VPS and dedicated servers
- Cloudways - Managed cloud hosting for developers