medusa icon indicating copy to clipboard operation
medusa copied to clipboard

Not able to use Medusa with Docker Compose

Open manikmi opened this issue 2 years ago • 4 comments

Bug report

Describe the bug

Hi Folks,

I am trying to setup docker compose environment with Medusa.

  1. Postgres v15
  2. Medusa Adi with API
  3. Medusa Storefront (the one comes which initializing Medusa)
  4. nginx While setting the env up, I am able to setup connections using the Docker compose

The product details page is not showing up in the storefront.

System information

Medusa version (including plugins): v1.3.21 Node.js version: 18 Database: Postgres v 15 Operating system: Mac Browser (if relevant):

Steps to reproduce the behavior

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

The product details should show up

Screenshots

image image

Code snippets

Docker Compose

version: '3.8'

services:

  db:
    image: postgres:15
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_PASSWORD: <some-password>
    volumes:
      - ./postgres/data/:/var/lib/postgresql/data

  admin:
    build: ./my-medusa-store
    command: npm run dev
    restart: always
    depends_on:
      - db
    links:
      - "db:database"
    ports:
      - 7001:7001
      - 9000:9000
    volumes:
      - ./my-medusa-store-storefront:/my-medusa-store-storefront
    

  storefront:
    build: ./my-medusa-store-storefront
    # image: storefront
    command: npm run start
    restart: always
    volumes:
      - ./my-medusa-store-storefront:/app
    depends_on:
      - admin
    links:
      - "db:database"
      - "admin:admin"
    ports:
      - 8000:8000
    environment:
      NODE_ENV: development

  webserver:
    image: nginx
    restart: always
    ports:
      - 80:80
    links:
      - "admin:admin"
      - "storefront:storefront"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - db
      - admin
      - storefront

I have created Docker for Storefront like this:

FROM node:18-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json package-lock.json ./
RUN  npm install --production

FROM node:18-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

RUN npm run build

FROM node:18-alpine AS runner
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["npm", "start"]

I have made updates in .env.local in storefront as:

NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost/adminapi
NEXT_PUBLIC_BASE_URL=http://localhost/adminapi
POSTGRES_URL=postgres://postgres:postgres@database:5432/medusa

The sample data is seeded into the platform. The initial load of the storefront is loading fine. But it fails as I click on any product to load details with the following error.

Application error: a server-side exception has occurred (see the server logs for more information).
Digest: 193452068

Could not find the logs to support this. Any help is deeply appreciated. Add any other context about the problem here

manikmi avatar Nov 05 '23 16:11 manikmi

Can somebody please lend a hand on this issue?

manikmi avatar Nov 10 '23 04:11 manikmi

This is an issue, I am also not able to run medusa in docker compose and the example that they have is pretty old. It would be great if there is some example for this.

sankalpsingha avatar Nov 10 '23 05:11 sankalpsingha

I have managed to get the standard installation of admin backend running, but I am not able to login, even though the user exists and has been seeded already :

version: "3.8"
services:
  backend:
    build:
      dockerfile: Dockerfile
    image: backend:latest
    container_name: medusa-server
    restart: always
    command: ["npm", "run", "start"]
    depends_on:
      - postgres
      - redis
    environment:
      DATABASE_URL: postgres://postgres:postgres@postgres:5432/medusa-docker
      REDIS_URL: redis://redis:6379
      NODE_ENV: production
      STORE_CORS: http://localhost
      JWT_SECRET: something
      COOKIE_SECRET: something

    volumes:
      - medusa-data:/data
    ports:
      - "8080:9000"

  postgres:
    image: postgres:10.4
    ports:
      - "5432:5432"
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: medusa-docker

  redis:
    image: redis
    container_name: cache
    volumes:
      - cache-data:/data
    expose:
      - 6379

volumes:
  medusa-data:
  db-data:
  cache-data:

sankalpsingha avatar Nov 10 '23 07:11 sankalpsingha

It just not able to authorize when running inside the container :

image

SyedAsimAliSE avatar Apr 14 '24 07:04 SyedAsimAliSE

The admin requires https when not running on localhost in order for it to set the cookie via set-cookie during the login http request. Most node libaries now have whitelists for which domains the cookie header is allowed to be set on, and by default its localhost or https.

jono-allen avatar May 31 '24 05:05 jono-allen