docker - Docker Compose 总是强制构建一个服务
问题描述
这是我的 docker-compose 文件的一部分:
version: "3.2"
services:
cachable_service:
image: my/cachable_service:x.x
build:
context: .
dockerfile: cachable_service_Dockerfile
service_in_development:
image: my/service_in_development:latest
build:
context: .
dockerfile: Dockerfile
depends_on:
- cachable_service
如何仅强制service_in_development
始终从头开始构建图像,以便在那里获取最新代码?
我已经查看cache_from
了文件参考中的选项docker-compose
,但我找不到任何关于它到底做什么的明确解释。
说明:
在这个问题中,我问的是使用docker-compose.yml
文件本身中的选项强制仅重建特定服务的选项。但是,如果命令行选项让我这样做,我现在也会很高兴。
另外,我说的是强制“重建”图像。不仅仅是服务的“娱乐”。
解决方案
您可以使用以下命令重建所有图像:
docker-compose up --build --force-recreate
强制重建一项服务:
docker-compose up --build --force-recreate service-name-here
文档中更有用的参数
Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...] Options: -d, --detach Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit. --no-color Produce monochrome output. --quiet-pull Pull without printing progress information --no-deps Don't start linked services. --force-recreate Recreate containers even if their configuration and image haven't changed. --always-recreate-deps Recreate dependent containers. Incompatible with --no-recreate. --no-recreate If containers already exist, don't recreate them. Incompatible with --force-recreate and -V. --no-build Don't build an image, even if it's missing. --no-start Don't start the services after creating them. --build Build images before starting containers. --abort-on-container-exit Stops all containers if any container was stopped. Incompatible with -d. -t, --timeout TIMEOUT Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10) -V, --renew-anon-volumes Recreate anonymous volumes instead of retrieving data from the previous containers. --remove-orphans Remove containers for services not defined in the Compose file. --exit-code-from SERVICE Return the exit code of the selected service container. Implies --abort-on-container-exit. --scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.
推荐阅读
- reactjs - GitHub 不允许我访问远程仓库中的子文件夹
- python - 使用python包时导入错误
- javascript - 如何将自定义表情符号转换为数组?
- python-3.x - Decouple Python 库中的 IP_NETWORK 和 IP_DEVICE 是什么意思?
- javascript - 使用保存在 vue.js 中的 cookie 中的 JWT 从我的 spring API 获取用户对象以进行持久登录
- android - CoroutineWorker 和 coroutineScope
- swagger - 如何使用请求标头配置 Swagger APIKey?
- python - 在 discord.py 中创建一个“成员”对象
- bash - apt-get 在使用循环结构时表现不同
- excel - 在 Excel VBA 中查找下标选项卡并将其替换为下标