Containerize a JavaScript React app using Docker and serve it via Nginx.
FROM node:alpine as builder
WORKDIR /usr/app
COPY package.json yarn.lock /usr/app/
RUN yarn install
COPY . .
RUN yarn build
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /usr/app/build /usr/share/nginx/html
CMD [ "nginx", "-g", "daemon off;" ]
# nginx.conf
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
tags: docker javascript react frontend