How to get the load balancer address from a Docker container? - docker

I have a web app running on a Docker container behind a load balancer, and in one of the responses I'm returning a callback URL. The problem is that the callback URL resolves to the Docker container name instead of the load balancer address (which is public).
How can I get the load balancer address to construct the callback URL?

Related

Docker swarm ngnix proxy on each node --> route to particular node

I have my aws load balancer setup to route any request with "/background" in url to node "background". I have 4 total notes behind the load balancer and it appears swarm load balances also. So while aws load balancer might route to node "background" another node might process the http request.
Each node has a web server in port 80 running the same application but I want url's with /background to be processed on the background node. Is this possible?

Getting host IP in a container from the request generated by a container on same host

I have a goland reverse proxy server and want to differentiate between requests generated by another container on the same VM from requests coming from another host and only allow request generated on the same VM. I know this can be achieved by connecting all the containers to some network, but that's doesn't fit in my scenario.
When a request is generated from another container on the same VM, the request includes container (or network interface) IP as RemoteAddr which keeps changing when network is recreated.
When the request is made from another VM, it includes IP of the VM instead of the container. As per my understanding the request never leaves the VM when request is made from container on the VM to another container on the same VM and therefore it contains IP of the container instead of IP of the VM.
Is there a way that i could differentiate the requests coming from container from the same VM vs requests from another VM.

Reload docker stack network configuration

I have multiple docker stacks that are connected over the same network. If I restart one of the stacks the internal ip addresses of the related stack container seems to change. That results in wrong service name resolutions in other stacks and containers. It seems that the internal docker name service doesn't recognize the network change.
If try to access other containers with ping from a stack container shell by the service name (for example ping my_stack_my_container_name) I got a successful return from a wrong IP address. When I use the full container name instead (ping my_stack_my_container_name.134.134234234123) the return comes from the right IP.
Is there any way to trigger a reload of the stack networking/name service?
are you sure it's not reloaded? check if the docker containers (that should connect to reloaded container) are not caching DNS query results. I had same issue in haproxy config and I placed following lines to force haproxy to hold values only for 1s:
resolvers docker
# well known docker dns server address
nameserver dns 127.0.0.11:53
#HAProxy will hold name-ip mapping for 1s, so for each request new container ip will be resolved, balancing load
hold valid 1s
(...)
backend stackName_app_backend
server stackName_app_service stackName_ServiceName:80 resolvers docker check

Direct requests only to one container of the docker swarm service

Is it possible to cause docker load balancer which uses round robin to direct requests only one container of global docker service deployed on multiple hosts? If this container goes down, requests will be forwarded to other running containers.
The only way i can think of is using external load balancer like nginx, but requires additional docker service.
You can acheive the same result by using replica mode and only having one replica of the container running. In this case you rely on Docker to ensure that an instance is always available.
Alternatively, the recommended way is to use an external load balancer. Check Use swarm mode routing mesh to see the different usages.

Rancher external subdomains

I need to set subdomains for apps in docker containers, not in internal rancher network but for public use. I have domain delegated to rancher server. And there is host property in almost all stacks from catalog, but it doesn't work. I guess i need to delegate domain using some rancher dns or setup nginx to proxy traffic to some rancher server but I can't find any.
What you need is add a load-balancer service, which then forwards 80/443 of the host to the container app/nginx/whatever.
So navigate to your stack, click on add service -> load balancer. Then you can chose either for wich domain to trigger ( or catch all, which i would do for now ) and then which target. There you select your app-container and the port the container has its app / httpd server running and thats basically it

Resources