I want to use Docker in order to be able to run an old application that requires PHP 5.3, while still having my other websites on my host server, running on the host Apache.
So I have siteA.com, siteB.com, siteC.com running on the host, using the host Apache / PHP / MySQL server, and I have siteZ.com that is installed in a Docker container, which should be using the container's Apache / PHP but the host MySQL server.
Here's a representation of the architecture I'd like to obtain :
My issue is that it seems like I can't run Apache in the container, since the port 80 is already in use on the host.
My goal would be that the people could access siteA.com, siteB.com, siteC.com and siteZ.com, without having to specify a different port for any of those websites.
I managed to get siteZ.com running by using port 8080, but it's obviously not an option.
Thanks
PS : Please note that I'm completly new to Docker.
Edit : You can find my working solution here. Thanks to VonC for showing me the way to go :)
Sure you can: in a container, you can run Apache on any port you want.
but when you do
docker
run
, then you need to map this container port to a host port (which won't be 80, since it is already taken, but for instance 8080That is called reverse proxy, and you could run on port 80 a NGiNX (in a container or not) which would then reverse proxy back to siteA, B or C (each running on different port, in container or not).
See for instance "Nginx reverse proxy with multiple ssl domain".
Your main Apache wouldn't run directly on port 80 anymore (or it could, if you put it in a container!)
The goal behind putting everything in its own container is isolation.
Not just filesystem isolation with chroot, or memory isolation, but also configuration isolation: in a container, an Apache always run (if you want) in 80/443, not matter how many Apache containers are running.
You just launch them with the proper host port mapping, but inside a container, the config remains fixed and identical.
Thanks to VonC's answer I managed to get it working but I slightly changed my architecture, resulting in 3 containers instead of only 1.
I have one container for each Apache / PHP version, and one container with Nginx as reverse proxy. I think you can easily adapt this to install Nginx on the host and change it's configuration to match the architecture I described in my question.
Note that as I'm new to Docker, and a noob regarding Linux system administration, there's probably some mistakes and things that don't make any sense in the following scripts, but it's working for me. Feel free to improve it :)
Nginx Reverse Proxy image
The Dockerfile :
Here's the referenced
proxy.conf
file :And I run it using the following bash script :
I have a
/home/antoineb/Docker/images/nginxproxy/virtualhosts
folder on my host that contains the followingdefault
file :Apache 2.2 + PHP 5.3 image
Dockerfile :
I'm launching it using the following script :
My websites are stored in /home/website.com/www, and my apache virtualhosts are stored on the host in
/home/antoineb/Docker/images/apache22php53/virtualhosts
.Apache 2.4 + PHP 5.6.9 image
Dockerfile :
My running script :
Again, my websites are stored in /home/website.com/www, and my apache virtualhosts are stored on the host in
/home/antoineb/Docker/images/apache24php56/virtualhosts
.You can use host-based routing in docker glue
https://github.com/muayyad-alsadi/docker-glue
it's a light-weight daemon that generates
haproxy
templates on the fly (you can define nginx template if you like) that watch container labels like thisin this setup the glue daemon will generate haproxy config so that traffic to wp1.example.com goes to wp1 container