Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2020 02:16
What would you like to do?
Dockerfile and nginx.conf that supports Angular's path-based routing
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`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
server {
listen ${PORT:-80};
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $$uri /index.html;
Copy link

mraible commented May 3, 2020

Commands that work:

docker run -p 4200:80 ng-notes
docker run -e PORT=1234 -p 4200:1234 ng-notes
heroku container:push web --remote docker
heroku container:release web --remote docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment