N
Nuxt3w ago
Far

Docker Cant Read Node Module for Nuxt

hello is anyone using nuxt in docker? im trying to run my nuxt project inside docker but it cant read the node_modules i've already try a lot approach but still cant read the node module
No description
No description
6 Replies
kapa.ai
kapa.ai3w ago
Hi @Far. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I can help with your Nuxt Docker issue. Based on the knowledge sources, there are several common problems that can cause Node modules to not be properly accessible in a Docker container with Nuxt: Missing .dockerignore file One common issue is not having a proper .dockerignore file. As mentioned in one of the examples:
I found the solution. I was missing the .dockerignore file, so my node_modules folder was copied over.
Stack Overflow Post You should create a .dockerignore file that includes:
node_modules
npm-debug.log
node_modules
npm-debug.log
Volume mounting issues If you're using Docker Compose with volumes, this can override your container's node_modules:
volumes:
- .:/app
- /app/node_modules
volumes:
- .:/app
- /app/node_modules
This was identified as an issue in one case:
When I remove the volumes from my docker-compose.yaml it works fine.
Stack Overflow Post Proper Dockerfile structure Here's an example of a working Dockerfile for Nuxt 3 from the documentation:
FROM node:22-alpine AS build
WORKDIR /app

RUN corepack enable

# Copy package.json and your lockfile
COPY package.json pnpm-lock.yaml .npmrc ./

# Install dependencies
RUN pnpm i

# Copy the entire project
COPY . ./

# Build the project
RUN pnpm run build

FROM node:22-alpine
WORKDIR /app

# Only `.output` folder is needed from the build stage
COPY --from=build /app/.output/ ./

# Change the port and host
ENV PORT 80
ENV HOST 0.0.0.0

EXPOSE 80

CMD ["node", "/app/server/index.mjs"]
FROM node:22-alpine AS build
WORKDIR /app

RUN corepack enable

# Copy package.json and your lockfile
COPY package.json pnpm-lock.yaml .npmrc ./

# Install dependencies
RUN pnpm i

# Copy the entire project
COPY . ./

# Build the project
RUN pnpm run build

FROM node:22-alpine
WORKDIR /app

# Only `.output` folder is needed from the build stage
COPY --from=build /app/.output/ ./

# Change the port and host
ENV PORT 80
ENV HOST 0.0.0.0

EXPOSE 80

CMD ["node", "/app/server/index.mjs"]
Nuxt Content Docker Deployment Host configuration Make sure you've set the HOST environment variable correctly:
ENV HOST=0.0.0.0
ENV HOST=0.0.0.0
This ensures Nuxt accepts connections from outside the container:
Nuxt has to be configured properly to accept connections from an outside network. Otherwise it refuses every connection that ist not from the host machine.
Stack Overflow Post If you could share your Dockerfile and docker-compose.yml (if you're using it), I could provide more specific guidance for your situation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@496668119851466752> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
HugoRCD
HugoRCD3w ago
@Far If you want I have this Dockerfile that I use in almost all my "basic" Nuxt projects that works well!
# Stage 1: Build Stage
FROM node:22.14.0-alpine AS build

WORKDIR /app

RUN corepack enable

COPY package.json pnpm-lock.yaml .npmrc ./

RUN pnpm install

COPY . .

RUN pnpm run build

# Stage 2: Final Stage
FROM node:22.14.0-alpine AS final

WORKDIR /app

COPY --from=build /app/.output .output

EXPOSE 3000

CMD ["node", ".output/server/index.mjs"]
# Stage 1: Build Stage
FROM node:22.14.0-alpine AS build

WORKDIR /app

RUN corepack enable

COPY package.json pnpm-lock.yaml .npmrc ./

RUN pnpm install

COPY . .

RUN pnpm run build

# Stage 2: Final Stage
FROM node:22.14.0-alpine AS final

WORKDIR /app

COPY --from=build /app/.output .output

EXPOSE 3000

CMD ["node", ".output/server/index.mjs"]
Far
FarOP3w ago
currently my nuxt inside a laravel folder as the root and inside the root also have docker file and docker-compose
Far
FarOP3w ago
No description
Far
FarOP3w ago
here the root docker file

Did you find this page helpful?