-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (24 loc) · 1.25 KB
/
Dockerfile
File metadata and controls
37 lines (24 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# syntax=docker/dockerfile:1
#Dockerfile for next.js
FROM node:24-alpine
# Must be root to prepare the directories; this command is implied, but being explicit for clarity
USER root
# Install curl
RUN apk add --no-cache curl
WORKDIR /app
# change owner to node user
RUN chown node:node /app
# If you mount a local folder in your compose.yaml, the host's permissions will overwrite whatever you did in the Dockerfile. To avoid permission issues, you can pre-create the .next directory and set the owner to `node` user. This way, when the container runs as non-root, it will have the necessary permissions to write to that directory.
# Pre-create the directory and set the owner to `node` user to ensure it is writable when the container runs as non-root
RUN mkdir -p /app/.next && chown -R node:node /app/.next
USER node
# Copy package*.json and install dependencies, as node user
COPY --chown=node:node ./package*.json ./
RUN npm install
# Copy the rest of the application, ensuring the ownership is set to node user
COPY --chown=node:node . ./
# Expose the port Next.js runs on during development
EXPOSE 3000
# Command to run the Next.js app in development mode
# This command should correspond to the "dev" script in your package.json
CMD ["npm", "run", "next-dev"]