A simple Docker deployment with just rsync and SSH
When people talk about Docker, somewhere along the lines the discussions quickly turns to Kubernetes, Mesosphere, or some other swarm orchestration technologies. It’s as if we are all led to believe Docker deployments are for deploying hundreds of containers at scale.
But the reality is, 99% of the deployments on the web will do just fine on a single container. Case in point, shared hosting typically hosts hundreds of websites on a single server, which powers half the web.
So no need to get all fancy and over complicate the matters as not everyone is at Google or Facebook scale. Even if you are getting hundreds of thousands of hits per day, a single container should be able to get by pretty easily. But if your app is designed horribly with i/o issues, not even Kubernetes can save you there. And if you are indeed getting Google level traffic, by then, I’m sure you have already found many ways to tackle the problem.
A simple approach that just works
So for the 95% of you who wants to reliably host a website using Docker, how do you do it?
Pre-requisite:
- a remote server with docker + docker-compose installed (https://docs.docker.com/engine/understanding-docker/)
- a remote server with jwilder/nginx-proxy docker image running (https://github.com/jwilder/nginx-proxy)
- your workstation with your codebase that includes a docker-compose.yml file in it with a VIRTUAL_HOST env set to a hostname / domain name
- your workstation with rsync and SSH access to the remote server (root or a user in docker group)
Now, deploy it!
Then from your application directory (let’s say your application lives in ~/sites/app.com), you simply type the following commands:
cd ~/sites/app.com
rsync -avzr . root@server.com:~/sites/
ssh root@server.com “cd ~/sites/app.com && docker-compose up -d”
If you remember the days of FTP’ing your website, this is pretty much that, except it now starts up all the services and servers along with it.
Now if you hate typing like me, you can just create a bash alias to make it easier. But if you are like me, you want it all done for you with a single command line interface, check out my project at http://hak.sh