Docker – Running multiple Nginx and MySQL instances within Docker containers

dockerweb-server

Could someone tell me if I am making correct use of Docker's workflow?

After reading about Docker and going through some brief tutorials, I see you can isolate services and applications within its containers. Ultimately, I'd love to replace virtualization with Docker but maybe I am taking this a bit too far.

I do application development with Laravel and implement using Nginx on Ubuntu. I would like to setup one large VPS and share its resources among 4 or 5 applications. That way I can keep different versions of PHP and dependencies and also isolate the web server and database (MySQL). The goal in doing this is to only share the Linux kernel and keep everything related to those applications within their respective containers.

Will services that require ports (e.g. Nginx/MySQL) need to be configured to use non-default port numbers in order to avoid conflict? Maybe I'm not completely understanding what Docker's intended use is but I was thinking you have the option of installing a web server outside of the container and share it with all respective projects or install several web servers – one for each container and tweak individually. Is that correct?

Best Answer

Use a frontend proxy like nginx (for relatively static backends) or hipache (for rapidly changing backends, for example if you are going to replace containers every hour or so and don't want to change the nginx config). The frontend proxy will listen on ports 80 and 443 and redirect the request to the right backend. I run 10 or so websites behind a single IP that way.