Build a docker image using unprivileged nginx

BREAKING CHANGE the exposed port has changed from 80 to 8080
This commit is contained in:
Hugh Nimmo-Smith 2023-01-20 13:31:14 +00:00
parent 2a1f9c5cad
commit d27aa137cf
3 changed files with 15 additions and 5 deletions

View File

@ -10,10 +10,17 @@ RUN yarn install
COPY . /app
RUN yarn build
FROM --platform=${BUILDPLATFORM} docker.io/nginx:alpine
# Because we will be running as an unprivileged user, we need to make sure that the config file is writable
# So, we will copy the default config to the /tmp folder that will be writable at runtime
RUN mv -f target/config.json /config.json.bundled \
&& ln -sf /tmp/config.json target/config.json
FROM --platform=${BUILDPLATFORM} docker.io/nginxinc/nginx-unprivileged:alpine
# Copy the dynamic config script
COPY ./docker/dynamic-config.sh /docker-entrypoint.d/99-dynamic-config.sh
# And the bundled config file
COPY --from=builder /config.json.bundled /config.json.bundled
# Copy the built app from the first build stage
COPY --from=builder /app/target /usr/share/nginx/html

View File

@ -55,7 +55,7 @@ Then, start up a container from that image:
```
docker run \
--name hydrogen \
--publish 80:80 \
--publish 8080:8080 \
hydrogen
```
@ -64,7 +64,7 @@ You can override the default `config.json` using the `CONFIG_OVERRIDE` environme
```
docker run \
--name hydrogen \
--publish 80:80 \
--publish 8080:8080 \
--env CONFIG_OVERRIDE='{
"push": {
"appId": "io.element.hydrogen.web",

View File

@ -2,7 +2,10 @@
set -eux
# Use config override environment variable if set
if [ -n "${CONFIG_OVERRIDE:-}" ]; then
echo "$CONFIG_OVERRIDE" > /usr/share/nginx/html/config.json
# Use config override environment variable if set
echo "$CONFIG_OVERRIDE" > /tmp/config.json
else
# Otherwise, use the default config that was bundled in the image
cp /config.json.bundled /tmp/config.json
fi