#medusa with docker cannot find module error

12 messages · Page 1 of 1 (latest)

subtle pivot
#

I'm new to docker but I want to run all medusa services like redis and postgres with docker, I get this error: Error in loading config: Cannot find module '/app/medusa-config', I think the issue is in my Dockerfile

docker-compose.yml

services:
  medusa:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "9000:9000"
  ...

Dockerfile:

FROM node:20

WORKDIR /app

COPY server/medusa /app

RUN npm install

EXPOSE 9000

CMD ["npm", "run", "dev"]
golden lagoon
#
FROM node:20.11.0 AS builder

WORKDIR /builder

COPY package*.json ./
RUN npm install

COPY --chown=node:node . .

RUN npm run build

FROM node:20.11.1

WORKDIR /app
COPY --from=builder /builder/.medusa/server /app
COPY --from=builder /builder/medusa-config.js /app/medusa-config.js
COPY --from=builder /builder/instrumentation.js /app/instrumentation.js
COPY --from=builder /builder/tsconfig.json /app/tsconfig.json

RUN npm install

ENV NODE_ENV="production"

# Port
EXPOSE 9000

CMD ["npm", "start"]

subtle pivot
#

Thanks, works after changing .js to .ts, or only copying /builder/.medusa/server (don't need the other copy's)
Can you explain why this works?

subtle pivot
#

This one works:

FROM node:20.11.0

WORKDIR /app

COPY server/medusa/package*.json /app

RUN npm install

COPY server/medusa /app

EXPOSE 9000

CMD ["npm", "run", "dev"]

Wonder why because it's very similar to the one I had originally!

golden lagoon
#

used for github workflows. need to compile first, then build the required files into an image

subtle pivot
#

Makes sense, but when copying from builder it seems enough to only copy the .medusa/server

golden lagoon
subtle pivot
#

It's already inside the .medusa/server/

wind pollen
#

Hi Muhannad and Summer! I am trying to dockerize as well but am not following it.

I only need the backend part, no frontend. I have this as Dockerfile:

FROM node:20.14.0 as build

WORKDIR /.medusa/server

COPY . .

RUN npm i

ENTRYPOINT ["sh", "-c", "npm run predeploy && npm run start"]

And this as docker-compose.yml:

version: "3.8"
services:
  backend:
    build:
      context: .
      dockerfile: Dockerfile
    image: backend:latest
    container_name: medusa-server
    depends_on:
      - redis
    environment:
      MEDUSA_WORKER_MODE: shared
      DATABASE_URL: postgres://[email protected]/birdblocker-medusa?ssl_mode=disable
      REDIS_URL: redis://cache
      NODE_ENV: production
      JWT_SECRET: some_jwt_secret
      COOKIE_SECRET: some_cookie_secret
    ports:
      - "9000:9000"

  redis:
    image: redis
    container_name: cache
    expose:
      - 6379

When I run docker compose up --build I get the following error at the end:

#

This is my project layout

subtle pivot
#

This worked for me:

FROM node:20.11.0

WORKDIR /app

COPY package*.json /app

RUN npm install

COPY . /app

EXPOSE 9000

CMD ["npm", "run", "start"]
solemn gale
#

@subtle pivot @wind pollen @golden lagoon
Hii please help me out I am facing an issue while accessing the admin.
/dashboard when I try to login it throws an error
Can you please share with me docker and docker compose file if you are using nginx please share with me as well