Search code examples
phpamazon-web-servicesdockerdocker-composelamp

Best deployment strategy with docker compose (LAMP stack)


I decided to start using docker in all my projects, and I'm interested in best practices, when it comes to deployment.

If I have a local docker environment, that is running a php-apache, mysql, and redis service, what's the best strategy when deploying? Do you have a custom docker-compose config for production, which removes the redis and mysql services (assuming you'd want those on their own dedicated server)?


Solution

  • There are a number of viable ways to run PHP containers in production, so it's a little hard to answer your question comprehensively. I'll offer a few options:

    • Use a container hosting service like Docker Cloud to host your PHP code with the built-in Apache service.
    • Use an orchestration service (like Swarm or Kubernetes) hosted on your own servers. You'll have more setup here, but it will also give you more control. There are also services that make this easier like Rancher or Codemason.
    • Run docker-compose on one machine. Sure, it's not horizontally scalable, but if you're just working on a side project or small app, you can run all your containers on one server to start.

    As a note on database containers, you can containerize your database, and assuming that you put the actual data in a volume and have a sensible backup system in place there's no reason that containers won't be safe. You probably want to start by running just one container for your database or by using a hosted database service as scaling a database across multiple containers can get complicated (but here's a little bit about how you might do it with MySQL).