Migrating noeldemartin.com to Docker
|Started:||January 08, 2019|
|Completed:||January 30, 2019|
I want to start migrating my server setup to Docker, so that it's easier to create or destroy services. The dream would be to eventually move into a container-based cloud provider, and forget about infrastructure as much as possible. But for now I'll stick to using Docker within a standard DigitalOcean droplet.
Started working on it.
After looking at the existing options to serve websites from different containers running on the same host, I decided to implement a couple of bash scripts to serve them using an nginx container. I decided to do it rather than installing nginx directly on the host because it's slightly more portable (I say slightly because it isn't a problem to install nginx somewhere else).
This approach is essentially the same that using nginx-proxy, but I wanted to do it manually to have more control on what's actually going on. They are simple scripts, so it isn't like this took me a lot of work, and I learned more about Docker and networks doing it.
I've published my scripts with a couple of working examples on github. I called it nginx-agora (because it creates a network where all the other containers "come together"). But as I already mention in the readme, I don't recommend anyone using this for production without understanding what's going on.
I've now completed migrating the website! I also used the opportunity to improve on two things: scheduling automatic backups and setting up cron tasks with docker.
To perform backups, I started using spatie's laravel-backup package. It's been one of those rare packages that works out of the box and didn't give me any problems :). I may send them a thank you postcard as they suggest. Specially enjoyable was the fact that I could use DigitalOcean Spaces to store the files. Double simplicity, everything working smoothly!
The other thing that didn't go so smooth was configuring cron jobs within docker containers. It would have been possible to configure the cron tasks from the host and invoke the commands using docker
exec. But I thought it'd be better to encapsulate as much as possible within the containers. The final approach I've taken is to use supervisor within a php container, the one serving the app, to launch both the cron and php-fpm daemons. This will also be useful in the future if I want to launch other daemons, for example queue workers. I had to tweak a couple of things to make it work (change default command from the php image, add config files, etc.). But I am happy with the final results.
So that's it for this iteration of the website!
Task completed 🎉