Reload docker stack network configuration

2019-07-31 04:26发布

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?

1条回答
成全新的幸福
2楼-- · 2019-07-31 05:04

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
查看更多
登录 后发表回答