WILT: Local Docker w' nginx front end and multiple back end PHP containers
Diagnosing a production problem, where in production the code was in multiple containers behind a docker swarm entrypoint. How to mock that locally?
Our production environment is nicely locked down, no command line access whatsoever, so trying to triage a problem in production is difficult. Especially when it's not your code, and none of the error logs were spitting out anything. Merf. I couldn't replicate the issue in my local environment; but that was a single container and a single nginx front end. How to replicate the multi-backend?
Multiple container back end
1 deploy:
2 mode: replicated
3 replicas: 2
4 placement:
5 max_replicas_per_node: 1
First I just multiplied the back end by two containers. Execute. PHP container failed as they were competing for the same incoming port.
Different ports for each back end
1 ports:
2 - "81-82:80"
This was a cool find - you can specify multiple ports that map to a container's port. More replicas, more ports to pick from. Wee! Start the container, nginx finds a container. Just the one with the original port :81. Have to tell it there's more
nginx told of multiple back-ends
1upstream myapp1 {
2 server host.docker.internal:81;
3 server host.docker.internal:82;
4}
5...
6 location / {
7 proxy_pass http://myapp1;
Combine the two upstream containers into a URL named myapp1
, where I get to specify the inbound ports. Docker, so use host.docker.internal
as the server name. Then change the location to pass to that upstream list rather than to the base one.
Success!!