webdevops / TYPO3-docker-boilerplate

:stew: TYPO3 Docker Boilerplate project (NGINX, Apache HTTPd, PHP-FPM, MySQL, Solr, Elasticsearch, Redis, FTP)
https://webdevops.io/projects/typo3-docker-boilerplate/
MIT License
232 stars 91 forks source link

Setting up the local hostnames #85

Closed elmar-hinz closed 8 years ago

elmar-hinz commented 9 years ago

This may be a little off topic. However, once having multiple dockers running locally the question pops up, how to address them easily.

How to map 192.168.56.2:8007 to typo7:80 and 192.168.56.2:8008 to typo8:80? Just to pick up 2 examples.

Is there an easy setup, maybe a graphical tool?

mblaschke commented 9 years ago

Easiest solution: Map the webserver to different ports and use a reverse proxy

With WebDevOps Vagrant VM there is a basic setup for this - you only have to change the defaullt configuration.

See https://github.com/webdevops/vagrant-development/blob/develop/provision/ansible/roles/docker-proxy/files/sites-enabled/001-proxy.conf

ipf commented 8 years ago

I'm using a local haproxy in conjunction with dnsmasq for that. So each instance is called by s.th. such as http://project1.dev that maps to localhost:8001 and so on

haproxy example config:

global
    daemon
    maxconn 4096

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:80
    acl is_site1 hdr_end(host) -i www.dev
    acl is_site2 hdr_end(host) -i intranet.dev
    acl is_site3 hdr_end(host) -i test.dev

    use_backend www if is_site1
    use_backend intranet if is_site2
    use_backend test if is_site3

backend www
    balance roundrobin
    option httpclose
    option forwardfor
    server s2 127.0.0.1:8000 maxconn 32

...
elmar-hinz commented 8 years ago

I describe an approach that is working on OS X with a vagrant based docker machine.

Install:

brew install haproxy

Redirect domains to localhost by editing /etc/hosts:

127.0.0.1   elmarhinz.typo3

Configure haproxy to map domains to ports like shown above:

[...]
  acl is_site1 hdr_end(host) -i elmarhinz.typo3
[...]
  server server1 192.168.56.2:8000 maxconn 32
elmar-hinz commented 8 years ago

All in all it is a lot of configuration to do by hand. To be improved.

elmar-hinz commented 8 years ago

Reflection:

Mapping domains to servers is the natural field of a DNS. Ipf suggests dnsmasq. Additionally a loadbalancer is used to map to ports. Like bying a whole factory to get a hammer.

Is it the right approach to map the docker servers to ports instead of giving them IP addresses? IP based a DNS alone would do the job or even simple entries in /etc/hosts.

mblaschke commented 8 years ago

New boilerplate (devel branch) is prepared for dinghy or dory and automatic nginx reverse proxy using VIRTUAL_HOST as docker environment variable

see https://github.com/codekitchen/dinghy and https://github.com/FreedomBen/dory

mblaschke commented 8 years ago

New boilerplate (devel branch) is prepared for dinghy or dory and automatic nginx reverse proxy using VIRTUAL_HOST as docker environment variable

see https://github.com/codekitchen/dinghy and https://github.com/FreedomBen/dory