Last active
January 18, 2023 01:20
-
-
Save andersondario/c684c64c1a3cfe7b086fbb15836eb871 to your computer and use it in GitHub Desktop.
Dockerfile for Angular
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
## Reference: https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/ | |
FROM node:14.20.1-alpine AS builder | |
ARG ENV_NAME | |
WORKDIR /app | |
ENV ENV_NAME ${ENV_NAME} | |
COPY package.json package-lock.json ./ | |
RUN npm install | |
COPY . . | |
RUN npm run build-${ENV_NAME} | |
FROM nginx:1.23.1-alpine | |
COPY --from=builder /app/dist/dashboard-app/ /usr/share/nginx/html | |
RUN mkdir -p /var/cache/nginx && \ | |
apk --no-cache add shadow && usermod -u 10014 nginx && \ | |
groupmod -g 10014 nginx && \ | |
apk del shadow && \ | |
chown -R nginx:nginx /usr/share/nginx/html && \ | |
chown -R nginx:nginx /var/cache/nginx && \ | |
chown -R nginx:nginx /var/log/nginx && \ | |
chown -R nginx:nginx /etc/nginx/conf.d && \ | |
chown -R nginx:nginx /etc/nginx/nginx.conf && \ | |
touch /var/run/nginx.pid && \ | |
chown -R nginx:nginx /var/run/nginx.pid && \ | |
sed -i 's/listen .*/listen 9005;/g' /etc/nginx/conf.d/default.conf | |
# The line above was there due security context configuration in Kubernetes that doesn't allow container start on port 80. | |
USER nginx | |
WORKDIR /usr/share/nginx/html | |
EXPOSE 9005 | |
CMD ["nginx", "-g", "daemon off;"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment