diff --git a/nextjs-static-ngnix/.dockerignore b/nextjs-static-ngnix/.dockerignore new file mode 100644 index 0000000..48183fa --- /dev/null +++ b/nextjs-static-ngnix/.dockerignore @@ -0,0 +1,10 @@ +.git +node_modules +out +.next +.vscode +.prettier* +/eslintrc* +TODO +.editorconfig +**.log \ No newline at end of file diff --git a/nextjs-static-ngnix/dockerfile b/nextjs-static-ngnix/dockerfile new file mode 100644 index 0000000..038854c --- /dev/null +++ b/nextjs-static-ngnix/dockerfile @@ -0,0 +1,34 @@ +# Statically build nextjs, deploy on ngnix +# To build: +# docker build -t nextjs-static -f ./dockerfile . + +# To run: +# docker run --rm -e 'PORT=80' -p 80:80 -d --name nextjs-static nextjs-static:latest + +FROM node:latest as builder + +WORKDIR /app +# install deps +COPY package.json yarn.lock ./ +RUN yarn --production --frozen-lockfile + +#copy the directory after install is done + + +COPY . . + +#export +RUN yarn next build && yarn next export + +#stage2 +FROM nginx:alpine + +COPY nginx /etc/nginx/ + +# ## Remove default nginx index page +RUN rm -rf /usr/share/nginx/html/* + +# # Copy static files from the builder +COPY --from=builder /app/out /usr/share/nginx/html + +ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file