Skip to content

Conversation

@Mactory
Copy link

@Mactory Mactory commented Jan 23, 2018

I have come across the problem, that I have one webserver where I want to mix my web-apps with some static websites. As I really like the easy, pluggable way of setting my web-apps up with nginx-proxy (+ let's encrypt companion), I wanted to use this infrastructure to also serve my static files.
I therefore added a new backend that configures nginx to directly serve static files from a mounted volume in the nginx-proxy container.
To allow for static containers to be stopped, I also added the possibility to include stopped containers via an environment variable.

Tim Schneider added 2 commits January 23, 2018 09:48
This is done by intruducing a new VIRTUAL_PROTO=static. The VIRTUAL_ROOT variable points to the static root which should be mounted into the container as volume. Often the container of the static website does not need to run, so I introduced a new environment variable INCLUDE_STOPPED_CONTAINERS that adds the -include-stopped flag to docker-gen
… is not set

This prevents the passing of arbitrary flags to docker-gen
@dhm116
Copy link

dhm116 commented Mar 7, 2018

I could have avoided having to spin up a dummy python web server to serve the assets if this had been available - looking forward to having this feature merged in!

@Mactory
Copy link
Author

Mactory commented May 24, 2018

I'm still interested in seeing this merged in. I updated the branch to be up-to-date with the upstream branch.

@adeel41
Copy link

adeel41 commented Oct 23, 2018

Why this is not pulled in yet? is this project dead?

@alexkoval123
Copy link

any updates?

@JonathonReinhart
Copy link

The biggest problem I see with this attempt is that it still requires that the volume with the static content be mounted into the nginx-proxy container, which must happen manually; nginx-proxy can't dynamically add new volume/bind mounts to itself.

The end result is that you have configuration split between two containers (or docker-compose.yml files):

  • nginx-proxy configuration determines where the static data is mounted
  • The source app container sets VIRTUAL_ROOT which must match the above path

I love the automatic configuration that nginx-proxy provides, but I can't use it for Dockerized web-apps which have static content I want to serve with NGINX. I landed here looking for a solution to that problem, but unfortunately due to the limitations listed above, I don't think this helps. Thanks though, @Mactory.

@buchdag
Copy link
Member

buchdag commented May 11, 2021

I'm probably missing a point here, but what avantage does this approach have over serving those static files from another nginx container behind nginx-proxy ?

@buchdag buchdag added kind/feature-request Issue requesting a new feature status/needs-more-info status/pr-needs-tests This PR needs new or additional test(s) labels May 11, 2021
@dhm116
Copy link

dhm116 commented May 11, 2021

I'm probably missing a point here, but what avantage does this approach have over serving those static files from another nginx container behind nginx-proxy ?

The advantage is precisely that: avoiding the need to spin up another instance of nginx solely for the use-case of serving static assets.

I would imagine same argument could be made for the uWSGI/FastCGI backends - what advantage does including those directly within nginx-proxy have over simply running another nginx container behind nginx-proxy with the appropriate configuration?

This is exactly why I responded to the PR with:

I could have avoided having to spin up a dummy python web server to serve the assets if this had been available - looking forward to having this feature merged in!

I'm not sure what the limitations of the Docker client SDK are (I can dig more later), but is it possible for docker-gen to update the volume mounts for a running container? That could theoretically address the concern that @JonathonReinhart raised regarding having to manually mount volumes within the nginx-proxy container directly - I'm just not certain if it's technically feasible or not 🤷

@JonathonReinhart
Copy link

is it possible for docker-gen to update the volume mounts for a running container?

@dhm116 I think it's easier to start with the question: "Is is possible to add a volume mount to a running container?"

The answer, I'm fairly certain, is unfortunately "No."

So unless you want docker-gen to modify the nginx container's config and restart it, I don't see how this is technically feasible.

@buchdag
Copy link
Member

buchdag commented May 11, 2021

I'm not sure what the limitations of the Docker client SDK are (I can dig more later), but is it possible for docker-gen to update the volume mounts for a running container? That could theoretically address the concern that @JonathonReinhart raised regarding having to manually mount volumes within the nginx-proxy container directly - I'm just not certain if it's technically feasible or not 🤷

Regarding this part, no there is no way to live update volumes on a running container. You have to stop it, re-create the container with the new volume and start it again.

Regarding docker-gen, it is not meant to change anything on running container beside signaling them after a template rendering.

@dhm116
Copy link

dhm116 commented May 11, 2021

Thanks for the insights @JonathonReinhart and @buchdag, very much appreciated. My gut was telling me that it wasn't possible, but I was hoping for something within the SDK that I was unfamiliar with 😞

I think I would tend to agree that having to explicitly mount volumes to the nginx-proxy configuration at runtime would not be very ideal or "clean".

Would an approach where nginx-proxy has standard, named volume(s) that could be utilized so that, rather than directly exposing the nginx certs or dhparam (or static assets) directories, these named volumes would become the interface used to mount certificates and, perhaps, static files? This should still enable the current pattern of being able to react to new containers starting with environment variables triggering template updates, with the named volumes being mapped to known destinations within the nginx-proxy container. Then anyone is free to create mount points to the named volumes however they choose, right? It was the first alternative that sprang to mind that might support the existing and static file hosting use-cases, so forgive me if I glossed over something or left anything important out 😊 Hopefully the underlying concept makes sense - but I can elaborate anything that may not.

@buchdag
Copy link
Member

buchdag commented May 11, 2021

The advantage is precisely that: avoiding the need to spin up another instance of nginx solely for the use-case of serving static assets.

I would imagine same argument could be made for the uWSGI/FastCGI backends

You still have to create a stopped container just to act as a support for the environment variable (if it's not stopped, I guess it kinda defeat the whole feature's point).

In contrast, if you're planning on using WSGI/FastCGI your backend container does exist and run, wether nginx-proxy is able to natively proxy this protocol to the backend or not.

I get that serving static file straight from nginx-proxy might be useful and the parallel made with the uWSGI/FastCGI backends but I'm really not sold on having to use stopped and/or useless containers to achieve this.

@buchdag
Copy link
Member

buchdag commented May 11, 2021

Regarding the volumes / VIRTUAL_ROOT issue pointed by @JonathonReinhart, correct me if I'm wrong but the FastCGI backend feature already work exactly this way, right ?

@buchdag buchdag added type/feat PR for a new feature and removed kind/feature-request Issue requesting a new feature labels Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/needs-more-info status/pr-needs-tests This PR needs new or additional test(s) type/feat PR for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants