From 703149d76d2e663ff4222e92f8a13becc304a3ca Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:46:12 +0000 Subject: [PATCH] Docker: allow configuration of HTTP listen port via env var (#28840) * Docker: allow configuration of HTTP listen port via env var * Update docs/install.md Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> * prettier --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- Dockerfile | 8 ++++++-- .../nginx-templates/default.conf.template | 4 ++-- docs/install.md | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) rename nginx/conf.d/default.conf => docker/nginx-templates/default.conf.template (90%) diff --git a/Dockerfile b/Dockerfile index d46924865c..3cab540bb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,8 +21,12 @@ FROM nginx:alpine-slim COPY --from=builder /src/webapp /app -# Override default nginx config -COPY /nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf +# Override default nginx config. Templates in `/etc/nginx/templates` are passed +# through `envsubst` by the nginx docker image entry point. +COPY /docker/nginx-templates/* /etc/nginx/templates/ RUN rm -rf /usr/share/nginx/html \ && ln -s /app /usr/share/nginx/html + +# HTTP listen port +ENV ELEMENT_WEB_PORT=80 diff --git a/nginx/conf.d/default.conf b/docker/nginx-templates/default.conf.template similarity index 90% rename from nginx/conf.d/default.conf rename to docker/nginx-templates/default.conf.template index 0ae5790374..06f33e08dd 100644 --- a/nginx/conf.d/default.conf +++ b/docker/nginx-templates/default.conf.template @@ -1,6 +1,6 @@ server { - listen 80; - listen [::]:80; + listen ${ELEMENT_WEB_PORT}; + listen [::]:${ELEMENT_WEB_PORT}; server_name localhost; root /usr/share/nginx/html; diff --git a/docs/install.md b/docs/install.md index 1c182cdd34..7830324ffc 100644 --- a/docs/install.md +++ b/docs/install.md @@ -60,6 +60,16 @@ would be: docker run --rm -p 127.0.0.1:80:80 -v /etc/element-web/config.json:/app/config.json vectorim/element-web ``` +The behaviour of the docker image can be customised via the following +environment variables: + +- `ELEMENT_WEB_PORT` + + The port to listen on (within the docker container) for HTTP + traffic. Defaults to `80`. + +### Building the docker image + To build the image yourself: ```bash