Python 在docker容器中运行时,如何在API路由文件中自动进行FASTAPI拾取更改?
我正在通过docker compose中创建一个名为“摄取数据”的服务,通过docker运行FastApi。我的Dockerfile:Python 在docker容器中运行时,如何在API路由文件中自动进行FASTAPI拾取更改?,python,docker,flask,docker-compose,fastapi,Python,Docker,Flask,Docker Compose,Fastapi,我正在通过docker compose中创建一个名为“摄取数据”的服务,通过docker运行FastApi。我的Dockerfile: FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7 # Environment variable for directory containing our app ENV APP /var/www/app ENV PYTHONUNBUFFERED 1 # Define working directory RUN
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
# Environment variable for directory containing our app
ENV APP /var/www/app
ENV PYTHONUNBUFFERED 1
# Define working directory
RUN mkdir -p $APP
WORKDIR $APP
COPY . $APP
# Install missing dependencies
RUN pip install -r requirements.txt
还有我的docker-compose.yml文件
version: '3.8'
services:
ingestion-service:
build:
context: ./app
dockerfile: Dockerfile
ports:
- "80:80"
volumes:
- .:/app
restart: always
我不知道为什么当我在我的应用程序的任何端点中进行任何更改时,它不会自动拾取任何更改。每次我都必须重建图像和容器。快速回答:是:)
在Dockerfile中,您可以将应用程序复制到/var/www/app中。docker文件中的指令在构建映像时执行(
docker build-t:
)如果以后更改代码,图像怎么会意识到这一点?
但是,当您执行/var/www/app下的
docker run
/docker compose up
命令时,您可以从主机将卷(目录)装入容器中。然后,您将能够更改本地目录中的代码,并且这些更改也将自动显示在容器中
也许您想将当前工作目录(包含您的应用程序的目录)装载到/var/www/app
volumes:
- .:/var/www/app