Docker Compose 始终强制构建一项服务

nem*_*emo 5 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
Run Code Online (Sandbox Code Playgroud)

如何强制只service_in_development从头开始构建图像,以便我在其中获取最新的代码?

我已经研究了文件参考cache_from中的选项docker-compose,但找不到任何关于它到底做什么的明确解释。

澄清:

在这个问题中,我询问了一个选项,可以使用以下选项强制重建特定服务:docker-compose.yml文件本身中的选项强制仅重建特定服务的选项。但是,如果命令行选项让我这样做,我现在也会对此感到满意。

另外,我正在谈论强制“重建”图像。不仅仅是服务的“娱乐”。

Krz*_*ski 1

您可以使用以下命令重建所有图像:

docker-compose up --build --force-recreate
Run Code Online (Sandbox Code Playgroud)

强制重建一项服务:

docker-compose up --build --force-recreate service-name-here
Run Code Online (Sandbox Code Playgroud)

文档中更多有用的参数

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.
Run Code Online (Sandbox Code Playgroud)