4
0

Dockerfile 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # syntax=docker/dockerfile:1.4
  2. # 1. For build React app
  3. FROM node:lts AS development
  4. # Set working directory
  5. WORKDIR /app
  6. #
  7. COPY package.json /app/package.json
  8. COPY package-lock.json /app/package-lock.json
  9. # Same as npm install
  10. RUN npm ci
  11. COPY . /app
  12. ENV CI=true
  13. ENV PORT=3000
  14. CMD [ "npm", "start" ]
  15. FROM development AS build
  16. RUN npm run build
  17. FROM development as dev-envs
  18. RUN <<EOF
  19. apt-get update
  20. apt-get install -y --no-install-recommends git
  21. EOF
  22. RUN <<EOF
  23. useradd -s /bin/bash -m vscode
  24. groupadd docker
  25. usermod -aG docker vscode
  26. EOF
  27. # install Docker tools (cli, buildx, compose)
  28. COPY --from=gloursdocker/docker / /
  29. CMD [ "npm", "start" ]
  30. # 2. For Nginx setup
  31. FROM nginx:alpine
  32. # Copy config nginx
  33. COPY --from=build /app/.nginx/nginx.conf /etc/nginx/conf.d/default.conf
  34. WORKDIR /usr/share/nginx/html
  35. # Remove default nginx static assets
  36. RUN rm -rf ./*
  37. # Copy static assets from builder stage
  38. COPY --from=build /app/build .
  39. # Containers run nginx with global directives and daemon off
  40. ENTRYPOINT ["nginx", "-g", "daemon off;"]