【发布时间】:2020-07-10 01:53:12
【问题描述】:
我在 8000 端口上运行 RESTful Django 项目,在 3000 端口上运行 React 项目。
对于开发,我将所有的网址都放在了前端
href='localhost:8000/api/name' 或 href='localhost:8000/api/address'。
现在我要投入生产了,我希望我的 href 是 href='mysite.com/api/name' 或 href='mysite.com/api/address'。我不知道该怎么做。
如何访问我的 RESTful 数据哪个在另一个容器上?
我找到了这个article,但认为它不适合生产。
docker-compose.yml
version: "3.2"
services:
backend:
build: ./backend
volumes:
- ./backend:/app/backend
ports:
- "8000:8000"
stdin_open: true
tty: true
command: python3 manage.py runserver 0.0.0.0:8000
depends_on:
- db
- cache
links:
- db
frontend:
build: ./frontend
volumes:
- ./frontend:/app
#One-way volume to use node_modules from inside image
- /app/node_modules
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
depends_on:
- backend
tty: true
command: npm start
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
volumes:
- "./mysql:/var/lib/mysql"
- "./.data/conf:/etc/mysql/conf.d"
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: temp
MYSQL_USER: root
MYSQL_PASSWORD: root
volumes:
mysql: {}
【问题讨论】:
-
你如何为你的 react 前端提供服务?你没有为此使用你的 Django 后端吗?