gpt4 book ai didi

Dockerized React/Flask App w/ nginx live updates/docker volumes(带有nginx实时更新/扩展坞卷的Dockerated Reaction/FlaskApp)

转载 作者:bug小助手 更新时间:2023-10-25 22:43:20 25 4
gpt4 key购买 nike



I am trying to set up a development environment for a web dev project that is a React app served by a flask backend using Nginx/Gunicorn (to be honest I'm not 100% on what exactly these do yet, especially Gunicorn). I followed a tutorial to create an app that meets my criteria, but I would like to be able to get live updates for my python/flask backend as well as the react frontend. I am trying to use docker volumes for this, but there is an issue.

我正在尝试为一个网络开发项目建立一个开发环境,这是一个由使用Nginx/Gunicorn的FASK后端提供服务的Reaction应用程序(老实说,我还不是100%了解它们到底做了什么,特别是Gunicorn)。我按照教程创建了一个符合我的标准的应用程序,但我希望能够获得我的python/flask后端以及Reaction前端的实时更新。我正在尝试使用码头卷,但有一个问题。


Here is my Dockerfile for the react client and my docker-compose file for the project:

以下是我的Reaction客户端的Docker文件和项目的docker-compose文件:


# Latest version of Node, use first image to create second image
FROM node:16-alpine as build-step

# Define working directory
WORKDIR /app

# Setting path variable on image (I think)
ENV PATH /app/node_modules/.bin:$PATH

# Copy dependencies
COPY package.json yarn.lock ./

# Copy app code
COPY ./src ./src

# Copy static web data
COPY ./public ./public

# Install dependencies and build the app (I think)
RUN yarn install
RUN yarn build


FROM nginx:stable-alpine
COPY --from=build-step /app/build /usr/share/nginx/html
COPY deployment/nginx.default.conf /etc/nginx/conf.d/default.conf

version: "3.7"

services:
api:
build:
context: .
dockerfile: Dockerfile.api
image: flask-app-api
client:
build:
context: .
dockerfile: Dockerfile.client
image: react-client
ports:
- "3000:80"
volumes:
- /app/node_modules
- .:/usr/share/nginx/html # See below

environment:
- WATCHPACK_POLLING=true

So I initially tried doing what most tutorials say and having a volume map .:/app but I think the issue is that my content is being served by Nginx so the content from my react build file is being copied to /usr/share/nginx/html and the original folder is no longer referenced hence the attempt at mapping it as seen above. This does not work which is why I'm here. So, my question is: how do I get live updates to my app in this environment or should I attempt to remove nginx from the equation for development purposes and only use it in the production environment?

所以我最初试着按照大多数教程所说的那样做,并有一个卷图。:/app,但我认为问题是我的内容是由nginx提供的,所以我的React构建文件中的内容被复制到/usr/share/nginx/html,并且原始文件夹不再被引用,因此尝试如上所示映射它。这不管用,这就是我来这里的原因。所以,我的问题是:我如何在这个环境中获得我的应用程序的实时更新,或者我应该尝试从开发的方程式中删除nginx,而只在生产环境中使用它?


更多回答

I'd suggest removing Docker from the equation for development purposes and only using it in the production environment. This solves problems like "live reloads don't work because Docker has an isolated filesystem", "I can't directly run my unit tests without a very long docker command", "I have to completely destroy and recreate my setup when I change my package dependencies", and other similar inconvinences.

出于开发目的,我建议将Docker从等式中删除,只在生产环境中使用它。这解决了诸如“实时重载不起作用,因为Docker有一个隔离的文件系统”、“我不能在没有非常长的docker命令的情况下直接运行我的单元测试”、“当我改变我的包依赖项时我必须完全销毁并重新创建我的设置”等问题,以及其他类似的不便。

优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com