Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while running backend on Docker #56

Closed
LukaszMielczarek opened this issue Jan 28, 2025 · 0 comments
Closed

Error while running backend on Docker #56

LukaszMielczarek opened this issue Jan 28, 2025 · 0 comments

Comments

@LukaszMielczarek
Copy link

LukaszMielczarek commented Jan 28, 2025

Hi,

I'm trying to dockerize Mercure project using docker-compose, however, even though I'm able to run it locally, each time when I try to run the backend inside container I get the following error :

docker compose up --build

[+] Building 1.3s (16/16) FINISHED docker:orbstack
=> [backend internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 508B 0.0s
=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 1) 0.0s
=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 6) 0.0s
=> [storefront internal] load metadata for docker.io/library/node:alpine 0.8s
=> [backend internal] load .dockerignore 0.0s
=> => transferring context: 1.01kB 0.0s
=> [storefront base 1/2] FROM docker.io/library/node:alpine@sha256:15b885c5e195296ba49bab32681b478e92eb0f255078a84ad29020b87b0bdcc6 0.0s
=> CACHED [storefront base 2/2] RUN apk add -f --update --no-cache nano bash curl && yarn global add turbo 0.0s
=> CACHED [storefront medusa 1/1] WORKDIR /app 0.0s
=> [backend] exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:467d566f87fb023f4a67629f118853a3b15b82d4f01101487a3869ec575197c7 0.0s
=> => naming to docker.io/library/phd-mvn-backend:latest 0.0s
=> [backend] resolving provenance for metadata file 0.0s
=> [storefront internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 508B 0.0s
=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 1) 0.0s
=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 6) 0.0s
=> [vendor internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 508B 0.0s
=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 1) 0.0s
=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 6) 0.0s
=> [vendor internal] load .dockerignore 0.0s
=> => transferring context: 1.01kB 0.0s
=> [storefront internal] load .dockerignore 0.1s
=> => transferring context: 1.01kB 0.0s
=> [vendor] exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:94cf19e7804e68aba7d53d2a156ff4845595b9f19bae6a832a6da7b79dc1c11c 0.0s
=> => naming to docker.io/library/phd-mvn-vendor:latest 0.0s
=> [storefront] exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:42021a14803f1ddd5602cc10657d75246a05ff94053a2f041d2c5df315456125 0.0s
=> => naming to docker.io/library/phd-mvn-storefront:latest 0.0s
=> [vendor] resolving provenance for metadata file 0.0s
=> [storefront] resolving provenance for metadata file 0.0s
[+] Running 8/8
✔ backend Built 0.0s
✔ storefront Built 0.0s
✔ vendor Built 0.0s
✔ Container phd-mvn-db Running 0.0s
✔ Container phd-mvn-cache Running 0.0s
✔ Container phd-mvn-backend Created 0.1s
✔ Container phd-mvn-vendor Created 0.0s
✔ Container phd-mvn-storefront Created 0.0s
Attaching to phd-mvn-backend, phd-mvn-cache, phd-mvn-db, phd-mvn-storefront, phd-mvn-vendor
phd-mvn-backend | ╔════════════════════════════════════════════════════════════════════════╗
phd-mvn-backend | ║ ║
phd-mvn-backend | ║ Medusa collects anonymous usage analytics ║
phd-mvn-backend | ║ to help improve Medusa for all users. ║
phd-mvn-backend | ║ ║
phd-mvn-backend | ║ If you'd like to opt-out, you can use medusa telemetry --disable
phd-mvn-backend | ║ ║
phd-mvn-backend | ║ ║
phd-mvn-backend | ╚════════════════════════════════════════════════════════════════════════╝
phd-mvn-db | 2025-01-28 10:08:33.839 UTC [118] FATAL: database "phd" does not exist
phd-mvn-backend | info: Connection established with the database "marketplace"
phd-mvn-backend | info: Database "marketplace" already exists
phd-mvn-backend | info: Updated .env file with "DB_NAME=marketplace"
phd-mvn-backend | error: Error in loading config: Cannot find module '/app/apps/backend/medusa-config'
phd-mvn-backend | Require stack:
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/common/dynamic-import.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/common/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/auth/token.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/auth/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/dist/commands/new.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/dist/create-cli.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/dist/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/cli.js
phd-mvn-backend | error: Error: Cannot find module '/app/apps/backend/medusa-config'
phd-mvn-backend | Require stack:
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/common/dynamic-import.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/common/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/auth/token.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/auth/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/utils/dist/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/dist/commands/new.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/dist/create-cli.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/dist/index.js
phd-mvn-backend | - /app/node_modules/@medusajs/cli/cli.js
phd-mvn-backend | at Function. (node:internal/modules/cjs/loader:1409:15)
phd-mvn-backend | at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/app/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
phd-mvn-backend | at defaultResolveImpl (node:internal/modules/cjs/loader:1060:19)
phd-mvn-backend | at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1065:22)
phd-mvn-backend | at Function._load (node:internal/modules/cjs/loader:1214:37)
phd-mvn-backend | at TracingChannel.traceSync (node:diagnostics_channel:322:14)
phd-mvn-backend | at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
phd-mvn-backend | at Module.require (node:internal/modules/cjs/loader:1495:12)
phd-mvn-backend | at require (node:internal/modules/helpers:135:16)
phd-mvn-backend | at dynamicImport (/app/node_modules/@medusajs/utils/src/common/dynamic-import.ts:15:18)
phd-mvn-backend | npm notice
phd-mvn-backend | npm notice New major version of npm available! 10.9.2 -> 11.0.0
phd-mvn-backend | npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.0.0
phd-mvn-backend | npm notice To update run: npm install -g [email protected]
phd-mvn-backend | npm notice
phd-mvn-backend exited with code 1
Gracefully stopping... (press Ctrl+C again to force)
dependency failed to start: container phd-mvn-backend exited (1)

My docker-compose binds the whole local repository, so there is no difference between dependencies locally and in containers.
I can't figure out what could be the reason of such a behavior.

Attaching Docker and docker-compose files.

Docker:

FROM node:alpine as base

RUN apk add -f --update --no-cache nano bash curl \
      && yarn global add turbo

FROM base as medusa
WORKDIR /app
ARG APP

ENV PATH="/app/node_modules/.bin:${PATH}"
CMD ["turbo", "run", "${APP}#dev","--env-mode=loose"]

Docker-compose:

name: "phd-mvm-dev"
services:

  postgres:
    image: postgres:${POSTGRES_VERSION:-latest}
    container_name: ${PROJECT_NAME:-phd-mvm}-db
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    networks:
      - phd-mvm-internal
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ]
      interval: 10s
      retries: 5
      start_period: 30s
      timeout: 10s

  redis:
    image: redis:${REDIS_VERSION:-latest}
    container_name: ${PROJECT_NAME:-phd-mvm}-cache
    expose:
      - 6379
    ports:
      - "6379:6379"
    networks:
      - phd-mvm-internal
    healthcheck:
      test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
      interval: 10s
      retries: 5
      start_period: 30s
      timeout: 10s

  backend:
    image: ${PROJECT_NAME:-phd-mvm}-backend:latest
    container_name: ${PROJECT_NAME:-phd-mvm}-backend
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      postgres:
        condition: service_healthy
        restart: true
      redis:
        condition: service_healthy
        restart: true
    environment:
      DATABASE_URL: ${POSTGRES_URL:-postgres://xxx:xxx@postgres:5432/marketplace?ssl_mode=disable}
      REDIS_URL: ${REDIS_URL:-redis://redis:6379}
      JWT_SECRET: ${JWT_SECRET:-some_jwt_secret}
      COOKIE_SECRET: ${COOKIE_SECRET:-some_cookie_secret}
      ADMIN_CORS: ${ADMIN_CORS:-http://vendor:7001,http://localhost:5173,http://localhost:9000,https://docs.medusajs.com}
      AUTH_CORS: ${AUTH_CORS:-http://vendor:7001,http://localhost:5173,http://localhost:9000,https://docs.medusajs.com}
      VENDOR_CORS: ${VENDOR_CORS:-http://vendor:7001,http://localhost:5173,http://localhost:9000,https://docs.medusajs.com}
      STORE_CORS: ${STORE_CORS:-http://storefront:8000,https://docs.medusajs.com}
    ports:
      - "9000:9000"
    entrypoint: [ "sh", "-c" ]
    command: >
      "
        cd ./apps/backend &&
        npx medusa db:setup --db ${POSTGRES_DB:-marketplace} &&
        yarn seed &&
        npx medusa user --email [email protected] --password xxx@xxxx &&
        cd ../.. && 
        yarn workspace backend dev
      "
    networks:
      - phd-mvm-internal
    volumes:
      - .:/app
      - phd-mvm-db-data:/app/shared

    healthcheck:
      test: [ "CMD-SHELL", "curl -f http://localhost:9000/health || exit 1" ]
      interval: 30s
      retries: 3
      start_period: 1m
      timeout: 10s

  storefront:
    image: ${PROJECT_NAME:-phd-mvm}-storefront:latest
    container_name: ${PROJECT_NAME:-phd-mvm}-storefront
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      backend:
        condition: service_healthy
        restart: true
    environment:
      MEDUSA_BACKEND_URL: http://backend:9000
      NEXT_PUBLIC_BASE_URL: http://localhost:8000
      #          WARN !!! Disable due to dynamically generating key
      #          NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      NEXT_PUBLIC_DEFAULT_REGION: us
      REVALIDATE_SECRET: supersecret
    #      NEXT_PUBLIC_STRIPE_KEY=
    ports:
      - "8000:8000"
    entrypoint: [ "sh", "-c" ]
    command: >
      "
        cat ./shared/.publishable_api_key >> ./apps/storefront/.env &&
        yarn workspace storefront dev
      "
    networks:
      - phd-mvm-internal
    volumes:
      - .:/app
      - phd-mvm-db-data:/app/shared

  vendor:
    image: ${PROJECT_NAME:-phd-mvm}-vendor:latest
    container_name: ${PROJECT_NAME:-phd-mvm}-vendor
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      backend:
        condition: service_healthy
        restart: true
    ports:
      - "7001:7001"
    entrypoint: [ "sh", "-c" ]
    command: >
      "
        yarn workspace vendor dev
      "
    networks:
      - phd-mvm-internal
    volumes:
      - .:/app
      - phd-mvm-db-data:/app/shared

networks:
  phd-mvm-internal:
    name: ${PROJECT_NAME:-phd-mvm}-network

volumes:
  phd-mvm-db-data:
    name: ${POSTGRES_VOLUME_NAME:-phd-mvm}-db-data

Regards

@LukaszMielczarek LukaszMielczarek closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant