【发布时间】:2020-03-23 08:25:11
【问题描述】:
我有一个分为两部分的应用程序:前端和后端。我的前端是一个 React JS 应用程序,我的后端是一个 Java Spring 启动应用程序。该项目在 Docker 中运行,有 3 个容器:前端、后端和 db(数据库)。我的问题是我不能做我的前端并向我的后端容器发送任何请求。以下是我的 Docker 配置文件:
Docker 撰写:
version: "3"
services:
db:
image: postgres:9.6
container_name: db
ports:
- "5433:5432"
environment:
- POSTGRES_PASSWORD=123
- POSTGRES_USER=postgres
- POSTGRES_DB=test
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: backend
ports:
- "8085:8085"
depends_on:
- db
frontend:
container_name: frontend
build:
context: ./frontend
dockerfile: Dockerfile
expose:
- "80"
ports:
- "80:80"
links:
- backend
depends_on:
- backend
Dockerfile 前端:
# Stage 0, "build-stage", based on Node.js, to build and compile the frontend
FROM node:8.12.0 as build-stage
WORKDIR /app
COPY package*.json /app/
RUN yarn
COPY ./ /app/
RUN yarn run build
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
FROM nginx
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build-stage /app/build/ /usr/share/nginx/html
# Copy the default nginx.conf provided by tiangolo/node-frontend
COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf
Dockerfile 后端:
FROM openjdk:8
ADD /build/libs/reurb-sj-13-11-19.jar reurb-sj-13-11-19.jar
EXPOSE 8085
ENTRYPOINT ["java", "-jar", "reurb-sj-13-11-19.jar", "--app.db.host=
我是否尝试向这些 Ip 发送请求:
- 本地主机:8085
- 172.18.0.3:8085
- 172.18.0.3
- 0.0.0.0:8085
当我尝试从前端发送请求时,它“启动”并等待大约 10 秒,然后返回错误。奇怪的是我的请求没有返回任何状态。
PS.:我已经阅读了所有互联网,每个人都说要放置 EXPOSE、PORTS 和 LINKS(在 docker-compose 中),我已经尝试过但仍然无法正常工作。
【问题讨论】:
标签: docker docker-compose dockerfile