I am starting to explore Docker through Docker for Mac using Docker Compose, with the intention of using it as a development environment for WordPress sites to be hosted on a Digital Ocean droplet.
On my regular DO droplet, I have nginx running with php-fpm and mysql, along with separate WordPress installs for each domain in /var/www/html. I’m trying to follow this approach in DC, but I’m not quite sure how to get there. None of the tutorials I’ve read explain how to have separate containers for each WordPress install, and separate containers each for nginx, php, mysql/mariadb, all supporting all of the WP sites. These are very low traffic sites.
Can someone suggest an approach to this with Docker Compose? Also, will this same approach for Docker for Mac and Docker Compose transfer to a DO droplet relatively seamlessly?
Here is something similar to to a site I did with docker compose, running on a single host machine. In this arrangement each Wordpress site is in a separate container. I used haproxy to direct the requests to the appropriate container.
In this case, each Wordpress server is running SSL locally and haproxy passes the HTTPS (SSL) request to the server. It is also possible (if you trust the connection to the servers to be private) to use haproxy to make the HTTPS connection and pass it as a HTTP to the servers.
Thank you very much for your detailed reply, Tom. I’m marginally familiar with HAproxy and load balancing. It looks like you are using it as an alternative to nginx. A quick search says there are differing views on the two approaches. Any particular reason to choose one over the other?
I think I might be able to work with your example compose file and use it as a model for my setup, so I’ll play with it and see. At the very least you’ve reinforced my basic approach to separate each wp site in its own container, and drive the nginx web server, php and mysql db each in their own containers supporting all of the wp sites. Thanks for the input.
nginx is a popular alternative to haproxy, particularly if the load balancing (or in this case routing based on requested website) is done at the http layer, rather than the tcp layer. nginx, used in the role of a load balancer/proxy, can perform all sorts of useful features like serving static content.
Because, in this case, the proxy is not doing much at the http layer, haproxy is a leaner proxy to use. It, also, when I checked had less known vulnerabilities than nginx. However, both are excellent and both will facilitate routing and load balancing to multiple backend servers per domain.
I was trying your script, and am getting the following errors
apache2: Could not open configuration file /etc/apache2/apache2.conf: No such file or directory
[ALERT] 169/000855 (1) : Cannot open configuration file/directory /usr/local/etc/haproxy/haproxy.cfg : No such file or directory
I understand that its indicating that the files are not in those directory’s, but I have moved my haproxy.cfg into the /etc/haproxy directory and installed apache2 and verified that the files are there, but am still getting the errors.
I have also cleared all images, containers, restarted docker, will no luck.