我对其中一项服务的 Dockerfile 进行了一些更新,但在运行时,这些更改并未反映出来docker-compose build
,甚至没有--no-cache
选择。
我在运行之前添加了两个参数pip install -f requirements.txt
,但它们不会在任何时候执行:它直接进入需求步骤。
$ docker-compose build --no-cache
mongo uses an image, skipping
postgres uses an image, skipping
elasticsearch uses an image, skipping
Building nucleo
Step 1/9 : FROM python:3.6
---> 2bb3204ab1d1
Step 2/9 : COPY core/ /container_core/
---> cc1eadcb80a3
Step 3/9 : WORKDIR /container_core
---> Running in e8afa25b9c9a
Removing intermediate container e8afa25b9c9a
---> f9b928dee6f5
Step 4/9 : RUN pip install -r requirements.txt
---> Running in 84f474edb526
^CERROR: Aborting.
docker-compose.yml
services:
mongo:
image: "mongo:4.0.5"
container_name: compose_mongo
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=mongo
- MONGO_INITDB_ROOT_PASSWORD=mongopass
ports:
- "27017:27017"
core:
build:
context: /home/ivanleoncz/git/core
dockerfile: Dockerfile
container_name: compose_core
depends_on:
- mongo
env_file:
- .env
ports:
- "8000:8000"
Dockerfile
FROM python:3.6
COPY core/ /container_core/
WORKDIR /container_core
# must run before requirements
RUN pip install --upgrade pip
RUN pip install urllib3=1.20
# then, run the requirements
RUN pip install -r requirements.txt
CMD ["python3", "manage.py", "makemigrations", "app1"]
CMD ["python3", "manage.py", "makemigrations", "app2"]
CMD ["python3", "manage.py", "makemigrations", "app3"]
CMD ["python3", "manage.py", "migrate"]
CMD ["python3", "manage.py", "runserver"]
我正在使用 docker-compose 1.21.2 和 Ubuntu 18.04.2。
docker-compose
尽管我描述了我想执行构建,但如何保证没有使用旧版本的Dockerfile,而没有任何缓存( --no-cache
)?
答案1
我从与标签上docker-compose build --no-cache
定义的目录不同的目录运行context
docker-compose.yaml。
core:
build:
context: /home/ivanleoncz/git/core
dockerfile: Dockerfile
在这个不同的目录中,我正在更新我的 Dockerfile,在上下文目录中,我有一个过时的 Dockerfile。
由于定义了上下文,因此/home/ivanleoncz/git/core/Dockerfile
在过程中考虑了它docker-compose build --no-cache
,而不是我当前目录中的 Dockerfile。