From 116d8d4b98ad872b46085e85b45ba839c773a033 Mon Sep 17 00:00:00 2001 From: Paul Philion Date: Thu, 22 Aug 2024 11:04:39 -0700 Subject: [PATCH] Refactoring to build to a busybox container --- Dockerfile | 18 +++++++++++------- compose.yml | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4286ff1..9b7fa9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ # Multi-stage # 1) Node image for building frontend assets -# 2) nginx stage to serve frontend assets +# 2) busybox stage to serve frontend assets # based on https://typeofnan.dev/how-to-serve-a-react-app-with-nginx-in-docker/ +# and https://lipanski.com/posts/smallest-docker-image-static-website FROM node:18 AS builder WORKDIR /app @@ -19,13 +20,16 @@ COPY . . RUN npm run build -# nginx state for serving content -FROM nginx:alpine +FROM busybox -WORKDIR /usr/share/nginx/html +# Create a non-root user to own the files and run our server +RUN adduser -D static +USER static +WORKDIR /home/static -# Copy static assets from builder stage +# Copy the static website +# Use the .dockerignore file to control what ends up inside the image! COPY --from=builder /app/build . -# Containers run nginx with global directives and daemon off -#ENTRYPOINT ["nginx", "-g", "daemon off;"] +# Run BusyBox httpd +CMD ["busybox", "httpd", "-f", "-v", "-p", "3000"] diff --git a/compose.yml b/compose.yml index c975377..5958446 100644 --- a/compose.yml +++ b/compose.yml @@ -2,5 +2,6 @@ services: ccn-coverage-vis: build: context: . + stop_grace_period: 1s ports: - - "8080:80" + - "8080:3000"