Long stories short, we had to develop a basic client register with a mySQL database (so goodbye Heroku). Everything was working as expected locally, but - I'm pretty sure you can see what's coming - the whole thing collapsed when we tried to deploy.
Let me share a post-mortem of what went wrong, before sharing a few tips on how to make your life easier with Docker.
The details of the app don't matter, but here's a tiny bit of context:
- We didn't anticipate that deployement would require a large amount of time, so we didn't start until the very last minute, which made the chaos and panic even worse.
- I had fiddled with Docker on a server in my free time, but couldn't make it work
So we chose a free hosting service, moved all the files on their server, and then nothing worked.
What seems to have happened is that the server was not running the same version of PHP we used to develop the website. It could have been avoided if we had done our research earlier, but hey, we learn from our mistakes.
Which brings me to the meat of this post: Deploying with Docker.
The little story above shows that the tricky thing with deploying your site or your app is that the environement provided by your host might differ considerably from your development environment. As a result, you need to anticipate and allocate time for deployment when planning your project.
Now, if you're reading this post and have already heard about Docker, you know where this is going: using Docker can make your life easier by replicating your development environment on your server, quite literally.
I'll let you follow the link if you want to learn what Docker is and how it does what it does. Let me just share how I used it to redeploy our site elsewhere and saved us some tedious work:
Choose your host.
I went for Digital Ocean, because it was recommended by someone I trust. It's not free though.
Install Docker on the server
It turns out Digital Ocean allows you to create VMs with Docker already installed. If you want to do it manually, just find a Ubuntu server and follow this tutorial (don't forget to install docker-compose).
docker-compose.ymlinto your server
That's the magic part: if you used Docker to set up your developement environment, you already have this file. All you need to do is to put it on a repository (GitHub, BitBucket, whatever you like) and clone it on your server.
Create the containers
Go to the folder that will contain your app, put the
docker-compose.ymlin it, then:
That's it. Well almost. At this point, you might need to restart the server for things to work. I don't know why, but I had to do it.
Now, all you need to do is clone your app's repository in the right folder on your server, and your app will run exactly as it did locally because it will be running in the exact same environment.
That should save you some time.