Skip to content

Commit f310925

Browse files
committed
Build a docker image using unprivileged nginx
BREAKING CHANGE the exposed port has changed from 80 to 8080
1 parent e08f0fe commit f310925

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ RUN yarn install
1010
COPY . /app
1111
RUN yarn build
1212

13-
FROM --platform=${BUILDPLATFORM} docker.io/nginx:alpine
13+
# Because we will be running as an unprivileged user, we need to make sure that the config file is writable
14+
# So, we will copy the default config to the /tmp folder that will be writable at runtime
15+
RUN mv -f target/config.json /config.json.bundled \
16+
&& ln -sf /tmp/config.json target/config.json
17+
18+
FROM --platform=${BUILDPLATFORM} docker.io/nginxinc/nginx-unprivileged:alpine
1419

1520
# Copy the dynamic config script
1621
COPY ./docker/dynamic-config.sh /docker-entrypoint.d/99-dynamic-config.sh
22+
# And the bundled config file
23+
COPY --from=builder /config.json.bundled /config.json.bundled
1724

1825
# Copy the built app from the first build stage
1926
COPY --from=builder /app/target /usr/share/nginx/html

doc/docker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Then, start up a container from that image:
5555
```
5656
docker run \
5757
--name hydrogen \
58-
--publish 80:80 \
58+
--publish 8080:8080 \
5959
hydrogen
6060
```
6161

@@ -64,7 +64,7 @@ You can override the default `config.json` using the `CONFIG_OVERRIDE` environme
6464
```
6565
docker run \
6666
--name hydrogen \
67-
--publish 80:80 \
67+
--publish 8080:8080 \
6868
--env CONFIG_OVERRIDE='{
6969
"push": {
7070
"appId": "io.element.hydrogen.web",

docker/dynamic-config.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
set -eux
44

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

0 commit comments

Comments
 (0)