Docker Compose:无法启动React应用服务器

时间:2020-05-14 20:57:53

标签: reactjs docker docker-compose

我正在尝试在Mac机器上使用docker启动react-springboot应用程序。我可以使用docker run命令单独启动服务器和客户端url,但是当docker compose启动失败时,react应用程序中会显示以下错误日志:

app-client_1 | 」wds」:项目正在http://172.20.0.2/运行 app-client_1 | 「wds」:Webpack输出从 app-client_1 | 「wds」:来自webpack的内容从/ app / public提供 app-client_1 | 「wds」:404会回退到/ app-client_1 |正在启动开发服务器... app-client_1 | react-proj_app-client_1以代码0退出 app-client_1 | app-client_1 | > my-app@0.1.0开始/ app app-client_1 | >反应脚本开始 app-client_1 |

以下是docker-compose.yml文件:

version: '3.7'
services:
  # App backend service
  app-server:
    # Configuration for building the docker image for the backend service
    build:
      context: demo
      dockerfile: Dockerfile
    ports:
      - "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine
    restart: always
    depends_on:
      - mysql-standalone # This service depends on mysql. Start that first.
    environment: # Pass environment variables to the service
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql-standalone:3306/my_db
      SPRING_DATASOURCE_USERNAME: sa
      SPRING_DATASOURCE_PASSWORD: password
    networks:
      - backend
      - frontend
  # Frontend Service
  app-client:
    build:
      context: my-app
      dockerfile: Dockerfile
      args:
          REACT_APP_API_BASE_URL: http://localhost:8080
    ports:
      - 3000:3000
    restart: always
    depends_on:
      - app-server
    networks:
      - frontend
    command: ["npm", "start"]
  # Database Service (Mysql)
  mysql-standalone:
    image: mysql:5.6
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_DATABASE: my_db
      MYSQL_USER: sa
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: some_password
    networks:
      - backend


  # Volumes
volumes:
  db-data:

  # Networks to be created to facilitate communication between containers
networks:
  backend:
  frontend:

这里可能是什么问题?

0 个答案:

没有答案