Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix template when running docker-gen and nginx in separate containers #750

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thomasleveil
Copy link
Contributor

Since commit 658e20f, the template makes the assumption that the container running docker-gen is the container running nginx while checking that upstream containers are reachable.

By introducing the NGINX_CONTAINER environment variable, users are now able to indicate which container is actually running nginx.

Since commit 658e20f, the template makes the assumption that the container running docker-gen is the container running nginx while checking that upstream containers are reachable.
By introducint the `NGINX_CONTAINER` environment variable, users are now able to indicate which container is actually running nginx when running docker-gen and nginx in separated containers.
@sjawhar
Copy link

sjawhar commented Apr 8, 2017

When using docker-compose, the container name is based on the project name (unless you set the container_name key, which is not very future-proof). Wouldn't it make more sense to have docker-gen look for a container with the NGINX_CONTAINER environment variable set on it? Instead of telling docker-gen which container is the reverse proxy, you set an environment variable on the reverse proxy that lets docker-gen discover it.

If you did that, though, I suppose you'd also need a way to pass that container name to the sighup command programmatically.

@thomasleveil
Copy link
Contributor Author

But then what about the case where you have multiple nginx-proxy containers?

@sjawhar
Copy link

sjawhar commented Apr 8, 2017

If there are multiple because you're replicating them in a stack, we should be able to figure out a way to use the service name. Using the current 'container_name' based logic, this is impossible anyway, since you can't scale past one container with that property set.

Otherwise, I'm not sure it's an issue. Nonetheless, I have two more ideas:

  1. maybe we set a matching environment variable on both the docker-gen service and the reverse-proxy service. Docker-gen looks for the reverse-proxy containers with the right value. A shared secret.
  2. My PR Compose v3: Moved shared volume to top-level volumes entry #709 uses a shared named volume. Maybe docker-gen can look for the service that shares that volume, since they're both attached to it?

@thomasleveil
Copy link
Contributor Author

thomasleveil commented Apr 8, 2017 via email

@sjawhar
Copy link

sjawhar commented Apr 8, 2017

All three of the ideas I proposed would work for your use case while not having the container_name limitation:

  1. NGINX_CONTAINER on nginx service: Since you have two different setups, and since docker-compose creates a default network for each project, each nginx/docker-gen pair is on its own network. Docker-gen could look for the container with the NGINX_CONTAINER variable that's in the same network as docker-gen.
  2. Shared secret: You set a different shared secret for each docker-gen/proxy pair.
  3. Shared volume: Each nginx/docker-gen pair also has it's own shared volume. Nothing extra to add here to support this use case.

That said, the shared volume method seems hacky. The shared network in 1 makes more sense.

@sgabe
Copy link
Contributor

sgabe commented Feb 15, 2020

Thanks @thomasleveil, this is very much needed when using separate containers. However, might be better to update the template in the docker-gen repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants