0
\$\begingroup\$

https://github.com/bbachi/nextjs-nginx-docker

https://github.com/bbachi/nextjs-nginx-docker/blob/main/Dockerfile

# stage1 as builder
FROM node:10-alpine as builder

# copy the package.json to install dependencies
COPY package.json package-lock.json ./

# Install the dependencies and make the folder
RUN npm install && mkdir /nextjs-ui && mv ./node_modules ./nextjs-ui

WORKDIR /nextjs-ui

COPY . .

# Build the project and copy the files
RUN npm run build


FROM nginx:alpine

#!/bin/sh

COPY ./.nginx/nginx.conf /etc/nginx/nginx.conf

## Remove default nginx index page
RUN rm -rf /usr/share/nginx/html/*

# Copy from the stahg 1
COPY --from=builder /nextjs-ui/out /usr/share/nginx/html

EXPOSE 3000 80

ENTRYPOINT ["nginx", "-g", "daemon off;"]

https://github.com/bbachi/nextjs-nginx-docker/blob/main/.nginx/nginx.conf

worker_processes 4;

events { worker_connections 1024; }

http {
    server {
        listen 80;
        root  /usr/share/nginx/html;
        include /etc/nginx/mime.types;

        location /appui {
            try_files $uri /index.html;
        }
    }
}

Wondering if there's anything that can make it faster.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

To make it faster?

(Assuming "it" is the build) Look into buildkit, see this SO question: https://stackoverflow.com/questions/65913706/how-do-i-make-yarn-cache-modules-when-building-containers

Otherwise, using yarn instead of npm might speed you up a little bit in the building process.

(Assuming "it" is the NextJS server (building)) Make sure that you are using Next version >12. The Rust compiler is MUCH faster than the javascript one.

(Assuming "it" is the NextJS server (running)) Make sure that all of your pages (or as many as possible) are statically generated. This allows the Next Server to serve them on demand instead of needing to Server Side Render them on demand.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.