Last active
December 30, 2022 03:24
-
-
Save NimJay/170c6678735a8f1dd68d89328e4f23e4 to your computer and use it in GitHub Desktop.
Dockerfile that hosts a Preact app, using NGINX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install Node dependencies. | |
FROM node:16-slim AS builder-stage | |
WORKDIR /app | |
COPY package.json package.json | |
COPY package-lock.json package-lock.json | |
RUN npm install | |
# Compile our TypeScript code. | |
COPY src/ src/ | |
COPY tsconfig.json tsconfig.json | |
RUN npm run build | |
# Use NGINX in a new Docker image to serve the static files. | |
FROM nginx:1.23 | |
COPY nginx.conf /etc/nginx/conf.d/default.conf | |
COPY --from=builder-stage /app/build/ /usr/share/nginx/html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Next to this
Dockerfile
, you will also need a file callednginx.conf
with contents:The main purpose of this
nginx.conf
is to make sure non-home routes in your Preact app do not 404 (via thetry_files $uri /index.html;
line).The only problem with this is that your server will never actually respond with a 404 status code — even when it should.