Skip to content

Instantly share code, notes, and snippets.

@mraible
Created May 3, 2020 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mraible/1a2f27352f9ec9c131938972680a1c71 to your computer and use it in GitHub Desktop.
Save mraible/1a2f27352f9ec9c131938972680a1c71 to your computer and use it in GitHub Desktop.
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 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
server {
listen ${PORT:-80};
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $$uri /index.html;
}
}
@mraible
Copy link
Author

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