【发布时间】:2019-11-20 23:51:45
【问题描述】:
我有以下docker-compose 文件:
version: "3"
services:
scraper-api:
build: ./ATPScraper
volumes:
- ./ATPScraper:/usr/src/app
ports:
- "5000:80"
test-app:
build: ./test-app
volumes:
- "./test-app:/app"
- "/app/node_modules"
ports:
- "3001:3000"
environment:
- NODE_ENV=development
depends_on:
- scraper-api
其中构建了以下Dockerfile's:
scraper-api(python flask 应用程序):
FROM python:3.7.3-alpine
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "./app.py"]
test-app(测试react api 应用程序):
# base image
FROM node:12.2.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:/app/src/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install --silent
RUN npm install react-scripts@3.0.1 -g --silent
RUN npm install axios -g
# start app
CMD ["npm", "start"]
诚然,我是 Docker 网络的新手,但我试图让 react 应用程序与 scraper-api 通信。例如,scraper-api 具有以下端点:/api/top_10。我尝试了以下网址的各种排列:
http://scraper-api:80/api/test_api。他们都没有为我工作。
我一直在搜索互联网,但我真的找不到解决方案。
【问题讨论】:
-
在您的
compose文件中使用networks或links
标签: docker docker-compose docker-networking