Skip to content

Commit db6371f

Browse files
committed
update the production Dockerfile to run as a non-privileged user
1 parent 10289a6 commit db6371f

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

apps/deployment/Dockerfile.prod

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ WORKDIR /model-catalog
1010
ENV PATH=/model-catalog/node_modules/.bin:$PATH
1111
COPY model_catalog/package.json ./
1212
COPY model_catalog/package-lock.json ./
13-
RUN npm ci --silent --legacy-peer-deps
13+
RUN npm ci --legacy-peer-deps
14+
1415
COPY model_catalog ./
1516
RUN node --max-old-space-size=4096 `which npm` run build
1617

@@ -25,8 +26,22 @@ RUN npm run build
2526

2627
# production environment
2728
FROM docker-registry.ebrains.eu/model-catalog/nginx:stable-alpine
29+
30+
RUN sed -i 's/^user nginx;/#user nginx;/' /etc/nginx/nginx.conf && \
31+
sed -i 's|/var/run/nginx.pid|/tmp/nginx.pid|' /etc/nginx/nginx.conf
32+
2833
COPY deployment/nginx-app.conf /etc/nginx/conf.d/default.conf
2934
COPY --from=build /model-catalog/dist /usr/share/nginx/html/model-catalog
3035
COPY --from=build /curation-dashboard/dist /usr/share/nginx/html/curation-dashboard
31-
EXPOSE 80
36+
37+
# Make nginx dirs writable for non-root user (UID 1001) — must come after COPY to preserve ownership
38+
RUN chown -R 1001:0 /var/cache/nginx /var/log/nginx /etc/nginx/conf.d /usr/share/nginx/html && \
39+
chmod -R g+w /var/cache/nginx /var/log/nginx /etc/nginx/conf.d /usr/share/nginx/html
40+
41+
COPY deployment/docker-entrypoint.sh /docker-entrypoint.sh
42+
RUN chmod +x /docker-entrypoint.sh
43+
44+
EXPOSE 8080
45+
USER 1001
46+
ENTRYPOINT ["/docker-entrypoint.sh"]
3247
CMD ["nginx", "-g", "daemon off;"]

apps/deployment/nginx-app.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
server {
5-
listen 80;
5+
listen 8080;
66

77
location / {
88
root /usr/share/nginx/html/model-catalog;

0 commit comments

Comments
 (0)