Search code examples
dockerdocker-composedocker-swarmdocker-machine

Production hosting for small scale website with docker-swarm


We had an old PHP website that we have rewritten in elixir. The previous page was hosted in the "old fashioned" way, code deployed to an FTP, sql managed via phpmyadmin.

I'm using docker-compose locally to run the database.

My plan is to host the new project on DigitalOcean by using only containers. I recently tried out docker-machine and could use a DO VM just as it was a local machine. I also read about docker-swarm but it is for multiple VMs with multiple containers for the same service.

My initial thought was to create just 1 docker-swarm manager and connect to that via docker-machine and execute a docker-compose command.

The goal is to have a solution that can be automated and maybe have 1 or 2 backup containers. But I'd avoid having multiple VMs because the site has only a couple hundred visitors a day.

Is this a viable solution or is there a simpler approach?


Solution

  • Some quick guidelines:

    1. Even if just a single server, I recommend enabling Swarm as you get new features and it's designed by default to keep a container running, and makes the process of updating/replacing that container easier (possible for zero downtime).
    2. If you use Swarm on the DO server, you could use docker stack deploy commands and you'd keep using docker-compose locally, and they could share same/similar compose files. The docker-compose command is just for local test/dev, and doesn't understand Swarm, but the file format is the same between the two.
    3. There's no reason to not use two or even three servers. Three managers would make it HA. You could use $5 servers if you needed to keep costs down (assuming the site runs in 1GB memory).
    4. Remember having multiple servers isn't just about capacity, it's about availability and fault tolerance. The great thing about Swarm is that it's designed to run 3 servers as easy as one. The commands are the same as a single VM.
    5. I wouldn't use docker-machine, but rather just try installing via instructions from store.docker.com for your Linux distribution, as you're better able to control the Docker version that way. For production, you'd want to stick with Stable quarterly releases (latest is 17.12).