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

时间:2019-03-28 18:57:49

标签: 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文件本身中的选项来强制仅重建特定服务的选项。但是,如果让我执行命令行选项,那么我现在也会对此感到满意。

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

1 个答案:

答案 0 :(得分: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.