Docker撰写始终强制构建一个服务

问题描述 投票:3回答:1

这是我的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 docker-compose
1个回答
0
投票

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

docker-compose up --build --force-recreate

强制重建一项服务:

docker-compose up --build --force-recreate service-name-here

documentation中更有用的参数

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.
© www.soinside.com 2019 - 2024. All rights reserved.