Created
May 3, 2020 02:16
-
-
Save mraible/1a2f27352f9ec9c131938972680a1c71 to your computer and use it in GitHub Desktop.
Dockerfile and nginx.conf that supports Angular's path-based routing
This file contains hidden or 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
FROM node:14.1-alpine AS builder | |
WORKDIR /opt/web | |
COPY package.json package-lock.json ./ | |
RUN npm install | |
ENV PATH="./node_modules/.bin:$PATH" | |
COPY . ./ | |
RUN ng build --prod | |
FROM nginx:1.17-alpine | |
RUN apk --no-cache add curl | |
RUN curl -L https://github.com/a8m/envsubst/releases/download/v1.1.0/envsubst-`uname -s`-`uname -m` -o envsubst && \ | |
chmod +x envsubst && \ | |
mv envsubst /usr/local/bin | |
COPY ./nginx.config /etc/nginx/nginx.template | |
CMD ["/bin/sh", "-c", "envsubst < /etc/nginx/nginx.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"] | |
COPY --from=builder /opt/web/dist/notes /usr/share/nginx/html |
This file contains hidden or 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
server { | |
listen ${PORT:-80}; | |
server_name _; | |
root /usr/share/nginx/html; | |
index index.html; | |
location / { | |
try_files $$uri /index.html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Commands that work: