byjg / docker-easy-haproxy

Discover services and create dynamically the haproxy.cfg based on the labels defined in docker containers or from a simple static Yaml
MIT License
56 stars 13 forks source link

Use container ip instead of container name when using the default bridge network #33

Closed josegonzalez closed 1 year ago

josegonzalez commented 2 years ago

After a bit of testing, it looks like if the containers aren't both in a custom network, they can't route to each other because the routing happens via the assumed network alias.

For the default bridge network:

If you run the same application stack on the default bridge network, you need to manually create links between the containers (using the legacy --link flag). These links need to be created in both directions, so you can see this gets complex with more than two containers which need to communicate. Alternatively, you can manipulate the /etc/hosts files within the containers, but this creates problems that are difficult to debug.

I think in this case, we want the internal ip address if the container is on the bridge network. Maybe we can have a "shadow" label that gets injected into the labels here and then pick it off later when we set the upstreams here?

byjg commented 2 years ago

I added a fix here

Instead of use the container/service name, which requires being in the same network, I get the IP. I need to run more tests with this solution.

byjg commented 2 years ago

Turns out, the solution wasn't simply get the container's IP Addresses.

Containers and services must share the same network as EasyHAProxy is. This PR will connect the container to the EasyHAProxy network, if the container is not previously connected.

josegonzalez commented 2 years ago

Neat. Looking forward to it landing in a release :)

josegonzalez commented 2 years ago

Ah one note: both containers are in the bridge network, so as long as that works as a test-case, then Dokku should be fine to use this :)

byjg commented 1 year ago

The issue with network was fixed in the version 4.3.0.