Like many software developers, I work on personal projects from time to time. To host them I use a VPS, and setting it up manually can be tricky. At first, I used the Vesta Control Panel for hosting my PHP and MySQL sites. Several years ago I switched from PHP/MySQL to Node JS/MongoDB, and now I had to configure my VPS manually. Although it’s pretty straightforward, it does take time and it’s not fun to troubleshoot when something goes wrong.
At some point, I realized that maintaining my server became too tedious: I had to take care of software updates, deployments, backups, and writing nginx configurations every time I had to host a new site.
Using Docker to host multiple projects on one VPS
Now let’s try to start from scratch and use Docker to host multiple projects on a single VPS. Why Docker? These factors mattered most for me:
- Every docker application contains its own environment and runs isolated.
- You can spin up your VPS from a single docker-compose.yml (and backed up data volumes).
- It separates code from data by using volumes.
- nginx-proxy makes it super easy to host multiple projects.
Here’s the list of services, software and Docker images that I used:
- GitLab for hosting docker-compose.yaml.
- Backblaze B2 for backups – it’s free for up to 10GB.
- LogDNA for log monitoring.
- Ubuntu – host OS.
- Docker and Docker Compose.
- jwilder/nginx-proxy – automatic nginx reverse proxy.
- jrcs/letsencrypt-nginx-proxy-companion – takes care of HTTPS. No configuration needed.
- php-apache and mariadb for PHP projects (like this blog).
- node-alpine and mongo for Node JS projects.
- nginx:alpine for static sites.
Setting up Docker host
Install the operating system of your choice, and do some primary setup. Configure firewall, set a custom SSH port, create a sudo user, and install Docker.
This is a docker-compose file that will get you started with nginx-proxy and letsencrypt.