gpt4 book ai didi

Docker-compose 不反射(reflect) requirements.txt 中的更改

转载 作者:行者123 更新时间:2023-12-04 18:55:48 27 4
gpt4 key购买 nike

我的变化 requirements.txt当我运行时没有被反射(reflect):

docker-compose -f docker-compose-dev.yml up -d

docker-compose-dev.yml


version: '3.6'

services:

web:
build:
context: ./services/web
dockerfile: Dockerfile-dev
volumes:
- './services/web:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres@web-db:5432/web_dev
- DATABASE_TEST_URL=postgres://postgres:postgres@web-db:5432/web_test
depends_on:
- web-db

web-db:
build:
context: ./services/web/project/db
dockerfile: Dockerfile
ports:
- 5435:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

nginx:
build:
context: ./services/nginx
dockerfile: Dockerfile-dev
restart: always
ports:
- 80:80
depends_on:
- web
- client

client:
build:
context: ./services/client
dockerfile: Dockerfile-dev
volumes:
- './services/client:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- 3007:3000
environment:
- NODE_ENV=development
- REACT_APP_WEB_SERVICE_URL=${REACT_APP_WEB_SERVICE_URL}
depends_on:
- web

Dockerfile-dev


# base image
FROM python:3.6-alpine

# install dependencies
RUN apk update && \
apk add --virtual build-deps gcc python-dev musl-dev && \
apk add libffi-dev && \
apk add postgresql-dev && \
apk add netcat-openbsd && \
apk add bind-tools && \
apk add --update --no-cache g++ libxslt-dev && \
apk add jpeg-dev zlib-dev

ENV PACKAGES="\
dumb-init \
musl \
libc6-compat \
linux-headers \
build-base \
bash \
git \
ca-certificates \
freetype \
libgfortran \
libgcc \
libstdc++ \
openblas \
tcl \
tk \
libssl1.0 \
"

ENV PYTHON_PACKAGES="\
numpy \
matplotlib \
scipy \
scikit-learn \
nltk \
"

RUN apk add --no-cache --virtual build-dependencies python3 \
&& apk add --virtual build-runtime \
build-base python3-dev openblas-dev freetype-dev pkgconfig gfortran \
&& ln -s /usr/include/locale.h /usr/include/xlocale.h \
&& python3 -m ensurepip \
&& rm -r /usr/lib/python*/ensurepip \
&& pip3 install --upgrade pip setuptools \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& ln -sf pip3 /usr/bin/pip \
&& rm -r /root/.cache \
&& pip install --no-cache-dir $PYTHON_PACKAGES \
&& pip3 install 'pandas<0.21.0' \
&& apk del build-runtime \
&& apk add --no-cache --virtual build-dependencies $PACKAGES \
&& rm -rf /var/cache/apk/*

# set working directory
WORKDIR /usr/src/app

# add and install requirements
COPY ./requirements.txt /usr/src/app/requirements.txt # <--- refer to EDIT
RUN pip install -r requirements.txt

# add entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh

RUN chmod +x /usr/src/app/entrypoint.sh

# add app
COPY . /usr/src/app

# run server
CMD ["/usr/src/app/entrypoint.sh"]

我错过了什么?

编辑

就像在 [ Docker how to run pip requirements.txt only if there was a change? 中接受的答案一样,我已经在复制 requirements.txt在将整个应用程序添加到图像之前,在单独的构建步骤中创建文件,但它似乎不起作用。

最佳答案

我认为问题可能是$ docker-compose up如果您进行更改,单独不会重建您的图像。为了得到docker-compose包括您对 requirements.txt 的更改您需要通过 --build标志到 docker-compose .

即改为运行:
docker-compose -f docker-compose-dev.yml up --build -d
这将强制 docker-compose重建图像。但是,这将重建 docker-compose 中的所有图像。可能需要也可能不需要的文件。

如果你只想重建单个服务的镜像,你可以先运行 docker-compose -f docker-compose-dev.yml build web ,然后运行你原来的 docker-compose命令。

更多信息 build命令 here .

关于Docker-compose 不反射(reflect) requirements.txt 中的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54845318/

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