代码之家  ›  专栏  ›  技术社区  ›  Tuomas Toivonen

docker合成,重建图像,不启动容器

  •  2
  • Tuomas Toivonen  · 技术社区  · 8 年前

    我docker compose,可以定义上下文如下

    version: '3'
    services:
        node1:
                build: node1
                image: node1
                container_name: node1
    
        node2:
                build: node2
                image: node2
                container_name: node2
    

    其中build是指包含Dockerfile和构建资源的目录。通过使用命令 docker-compose up -d --build 可以重建图像并重新启动已更改的容器。但是使用下面的docker compose文件,是否可以只生成图像而不启动它们,并且最好选择要生成的图像或全部生成?

    2 回复  |  直到 8 年前
        1
  •  4
  •   sp0gg    8 年前

    您可以构建特定的服务,而不必像这样启动它们:

    docker-compose build node1

    要构建它们:

    docker-compose build

        2
  •  2
  •   fly2matrix    8 年前

    docker-compose up --no-start
    它将执行构建、创建网络、创建卷而不启动容器。

    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.