Dockerized webapp - 热重新加载

问题描述 投票:0回答:1

我刚刚使用nginx,webpack,flaskapp和postgres的应用程序停靠,但是我目前必须运行:

docker-compose up --build

实现任何在重新创建整个环境时非常缓慢的更改,但它可以正常工作。

我想添加webpack的热重新加载功能,但是尽管经过数小时的搜索,我仍然在努力从概念上理解我需要做些什么来让它运行?

即使我创建一个单独的容器来运行webpack-dev-server插件,如何设置它来识别更改并与烧瓶后端通信?

这是我的dockerfile和docker-compose.yml文件......我对docker很新,所以任何指针都会非常感激!

Dockerfile

FROM ubuntu:latest

# Update the apt-get list
RUN apt-get update -y

# Install python packages
RUN apt-get install -y python-pip
RUN mkdir -p /opt/services/flaskapp/src
COPY requirements.txt /opt/services/flaskapp/src/
WORKDIR /opt/services/flaskapp/src
RUN pip install -r requirements.txt

# Install curl
RUN apt-get install -y curl

# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash
RUN apt-get install -y nodejs

# Install webpack globally
RUN npm install webpack -g

COPY . /opt/services/flaskapp/src
RUN npm run build
EXPOSE 5090
CMD ["python", "app.py"]

泊坞窗,compose.yml

version: '3'
services:
  db:
    image: "postgres:9.6.5"
    volumes:
      - "dbdata:/var/lib/postgresql/data"
    env_file:
      - env_file
    networks:
      - db_nw
  flaskapp:
    build: .
    env_file:
      - env_file
    volumes:
      - .:/opt/services/flaskapp/src
    networks:
      - db_nw
      - web_nw
    depends_on:
      - db
  nginx:
    image: "nginx:1.13.5"
    ports:
      - "8080:80"
    volumes:
      - ./conf.d:/etc/nginx/conf.d
    networks:
      - web_nw
    depends_on:
      - flaskapp
networks:
  db_nw:
    driver: bridge
  web_nw:
    driver: bridge
volumes:
  dbdata:
docker webpack web-applications webpack-dev-server
1个回答
0
投票

Flask支持在调试模式下重新加载代码。所以你应该做的是在你的env_file中指定以下内容:

  FLASK_DEBUG=1 (or True)
  FLASK_APP=./app.py

有了这个你也可以改变CMD部分如下:

  CMD ["python", "-m" "flask run"]

对于生产环境而言,请记住,最好使用gunicorn而不是简单的烧瓶app运行

© www.soinside.com 2019 - 2024. All rights reserved.