Reputation: 3
i want to containerize my (React + vire)frontend and (node + express) backend project in to one image and the db (mongo) in a separate image, i am on windows 11 docker desktop and i have write the Dockerfile and docker-compose.yml but after it build, and the container is created the app is getting error,
app | /app/frontend/node_modules/rollup/dist/native.js:64
app | throw new Error(
app | ^
app |
app | Error: Cannot find module @rollup/rollup-linux-x64-gnu. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
app | at requireWithFriendlyError (/app/frontend/node_modules/rollup/dist/native.js:64:9)
app | at Object.<anonymous> (/app/frontend/node_modules/rollup/dist/native.js:73:76)
app | ... 3 lines matching cause stack trace ...
app | at Module._load (node:internal/modules/cjs/loader:1104:12)
app | at cjsLoader (node:internal/modules/esm/translators:346:17)
app | at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:286:7)
app | at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
app | at async ModuleLoader.import (node:internal/modules/esm/loader:473:24) {
app | [cause]: Error: Cannot find module '@rollup/rollup-linux-x64-gnu'
app | Require stack:
mongo | {"t":{"$date":"2025-02-12T13:38:51.736+00:00"},"s":"I", "c":"WTCHKPT", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1739367531,"ts_usec":736737,"thread":"1:0x7f805ab82680","session_name":"WT_SESSION.checkpoint","category":"WT_VERB_CHECKPOINT_PROGRESS","category_id":7,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"saving checkpoint snapshot min: 1, snapshot max: 1 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 24"}}}
app | - /app/frontend/node_modules/rollup/dist/native.js
app | at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15)
app | at Module._load (node:internal/modules/cjs/loader:1051:27)
app | at Module.require (node:internal/modules/cjs/loader:1311:19)
app | at require (node:internal/modules/helpers:179:18)
app | at requireWithFriendlyError (/app/frontend/node_modules/rollup/dist/native.js:46:10)
app | at Object.<anonymous> (/app/frontend/node_modules/rollup/dist/native.js:73:76)
app | at Module._compile (node:internal/modules/cjs/loader:1469:14)
app | at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
app | at Module.load (node:internal/modules/cjs/loader:1288:32)
app | at Module._load (node:internal/modules/cjs/loader:1104:12) {
app | code: 'MODULE_NOT_FOUND',
app | requireStack: [ '/app/frontend/node_modules/rollup/dist/native.js' ]
app | }
app | }
app |
app | Node.js v20.18.3
and here is the project structure
Full/
│── backend/ # Express.js Backend
│ │ ── models/ # Mongoose models
│ │ ── routes/ # Express routes
│ │ ── uploads/videos # Uploaded media files
│ │ ── server.js # Main Express app
│ │── .env # Environment variables
│ └── package.json # Node.js dependencies
│
│── frontend/ # React + Vite Frontend
│ │── public/
│ │── src/
│ │ │── components/ # UI components
│ │ │── config/ # configurations
│ │ │── pages/ # Pages
│ │ │── App.jsx/ # Routes
│ │ └── main.jsx # Entry point
│ │── .env # Frontend environment variables
│ │── vite-config.js # vite configuration files
│ └── package.json # Frontend dependencies
│
│── Dockerfile # Combined Frontend + Backend Dockerfile (placed here)
│── .dockerignore # Ignore unnecessary files
│── docker-compose.yml # Compose file for services
└── README.md # Project documentation
my Dockerfile is like
# FROM node:21
FROM node:20-slim
# Set the working directory inside the container
WORKDIR /app
# Copy package files for backend and frontend
COPY backend/package.json ./backend/
COPY frontend/package.json ./frontend/
# Install dependencies for backend and frontend
RUN cd backend && npm install
RUN cd frontend && npm install
# Copy both backend and frontend source code
COPY backend ./backend
COPY frontend ./frontend
# Expose necessary ports (Frontend + Backend)
EXPOSE 3029 5173
# Default command (will be overridden by docker-compose)
CMD ["sh", "-c", "cd backend && npm start"]
here is my docker-compose.yml
version: '3.8'
services:
app:
build: .
container_name: kgs_app
ports:
- "3029:3029" # Backend
- "5173:5173" # Frontend
volumes:
- .:/app
- backend_node_modules:/app/backend/node_modules
- frontend_node_modules:/app/frontend/node_modules
environment:
- .....
depends_on:
- mongo
command: sh -c "cd backend && npm run dev & cd frontend && npm run dev"
mongo:
image: mongo:latest
container_name: kgs_mongo
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
environment:
- MONGO_INITDB_DATABASE=queuemangementsystem
volumes:
mongo_data:
backend_node_modules:
frontend_node_modules:
Upvotes: 0
Views: 61