0

我想完全通过 docker 部署我的 saleor-shop 应用程序。所以我为销售或后端、店面和仪表板构建了各自的图像。

在本地运行应用程序工作正常。后端在 localhost:8000/graphql 上可用 店面在 localhost:3000 运行 仪表板在 localhost:9000 运行

如果我想在 droplet IP 上运行应用程序 --> 我遇到了运行 saleor 后端的问题。截至目前,尝试访问 XXX.XX.XXX.XXX:8000 会导致“无法访问此站点”。店面和仪表板可在 XXX.XX.XXX.XXX:3000 和 XXX.XX.XXX.XXX:9000 上访问,但没有与后端进行任何交互,导致其不可用。这就是为什么 graphql 调用在店面不起作用并且登录到仪表板也不起作用,因为后端不可用。我想我在这里遗漏了一些东西,希望能得到任何帮助。

[Saleor店面][1] 销售员仪表板

在我的液滴中,我使用以下 docker-compose.yml 文件来启动我的 docker 容器:

services:
  api:
    ports:
      - 8000:8000
    image: XXX/murukku-shop
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    depends_on:
      - db
      - redis
      - jaeger
    env_file: common.env
    environment:
      - JAEGER_AGENT_HOST=jaeger
      - STOREFRONT_URL=http://XXX.XX.XXX.XXX:3000/
      - DASHBOARD_URL=http://XXX.XX.XXX.XXX:9000/

  storefront:
    image: XXX/murukku-storefront
    ports:
      - 3000:80
    restart: unless-stopped

  dashboard:
    image: XXX/murukku-dashboard
    ports:
      - 9000:80
    restart: unless-stopped

  db:
    image: library/postgres:11.1-alpine
    ports:
      - 5432:5432
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    volumes:
      - saleor-db:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=saleor
      - POSTGRES_PASSWORD=saleor

  redis:
    image: library/redis:5.0-alpine
    ports:
      - 6379:6379
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    volumes:
      - saleor-redis:/data

  worker:
    image: XXX/murukku-shop
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    env_file: common.env
    depends_on:
      - redis
      - mailhog
    environment:
      - EMAIL_URL=smtp://mailhog:1025

  jaeger:
    image: jaegertracing/all-in-one
    ports:
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "16686:16686"
      - "14268:14268"
      - "9411:9411"
    restart: unless-stopped
    networks:
      - saleor-backend-tier

  mailhog:
    image: mailhog/mailhog
    ports:
      - 1025:1025 # smtp server
      - 8025:8025 # web ui. Visit http://localhost:8025/ to check emails
    restart: unless-stopped
    networks:
      - saleor-backend-tier

volumes:
  saleor-db:
    driver: local
  saleor-redis:
    driver: local
  saleor-media:

networks:
  saleor-backend-tier:
    driver: bridge

4

1 回答 1

3

我在 docker 设置中像你一样测试 Saleor,我找到了解决方案!您必须设置更多的环境变量,它们都在店面的 github 页面和仪表板中进行了说明。如果需要,这是我的配置:

version: '2'

services:
  api:
    ports:
      - 8000:8000
    build:
      context: ./saleor
      dockerfile: ./Dockerfile
      args:
        STATIC_URL: '/static/'
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    depends_on:
      - db
      - redis
      - jaeger
    volumes:
      - ./saleor/saleor/:/app/saleor:Z
      - ./saleor/templates/:/app/templates:Z
      - ./saleor/tests/:/app/tests
      # shared volume between worker and api for media
      - saleor-media:/app/media
    command: python manage.py runserver 0.0.0.0:8000
    env_file: common.env
    environment:
      # - DEFAULT_CURRENCY=EUR
      #- DEFAULT_COUNTRY=
      - ALLOWED_CLIENT_HOSTS=localhost,127.0.0.1,192.168.0.50
      - ALLOWED_HOSTS=localhost,192.168.0.50
      - JAEGER_AGENT_HOST=jaeger
      - STOREFRONT_URL=http://192.168.0.50:3000/
      - DASHBOARD_URL=http://192.168.0.50:9000/

  storefront:
    build:
      context: ./saleor-storefront
      dockerfile: ./Dockerfile.dev
    ports:
      - 3000:3000
    restart: unless-stopped
    volumes:
      - ./saleor-storefront/:/app:cached
      - /app/node_modules/
    command: npm start -- --host 0.0.0.0
    environment: 
      - NEXT_PUBLIC_API_URI=http://192.168.0.50:8000/graphql/
      - API_URI=http://192.168.0.50:8000/graphql/

  dashboard:
    build:
      context: ./saleor-dashboard
      dockerfile: ./Dockerfile.dev
    ports:
      - 9000:9000
    restart: unless-stopped
    volumes:
      - ./saleor-dashboard/:/app:cached
      - /app/node_modules/
    command: npm start -- --host 0.0.0.0
    environment: 
      - API_URI=http://192.168.0.50:8000/graphql/
      - APP_MOUNT_URI=/dashboard/
      - STATIC_URL=http://192.168.0.50:9000/

  db:
    image: library/postgres:11.1-alpine
    ports:
      - 5432:5432
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    volumes:
      - saleor-db:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=saleor
      - POSTGRES_PASSWORD=saleor

  redis:
    image: library/redis:5.0-alpine
    ports:
      - 6379:6379
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    volumes:
      - saleor-redis:/data

  worker:
    build:
      context: ./saleor
      dockerfile: ./Dockerfile
      args:
        STATIC_URL: '/static/'
    command: celery -A saleor --app=saleor.celeryconf:app worker --loglevel=info
    restart: unless-stopped
    networks:
      - saleor-backend-tier
    env_file: common.env
    depends_on:
      - redis
      - mailhog
    volumes:
      - ./saleor/saleor/:/app/saleor:Z,cached
      - ./saleor/templates/:/app/templates:Z,cached
      # shared volume between worker and api for media
      - saleor-media:/app/media
    environment:
      - EMAIL_URL=smtp://mailhog:1025

  jaeger:
    image: jaegertracing/all-in-one
    ports:
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "16686:16686"
      - "14268:14268"
      - "9411:9411"
    restart: unless-stopped
    networks:
      - saleor-backend-tier

  mailhog:
    image: mailhog/mailhog
    ports: 
      - 1025:1025 # smtp server
      - 8025:8025 # web ui. Visit http://localhost:8025/ to check emails
    restart: unless-stopped
    networks:
      - saleor-backend-tier

volumes:
  saleor-db:
    driver: local
  saleor-redis:
    driver: local
  saleor-media:

networks:
  saleor-backend-tier:
    driver: bridge

PS:这是我在stackoverflow上的第一个答案:D如果我解决了你的问题,别忘了给我打勾;)

于 2021-01-28T20:38:40.173 回答