我是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文件,是否可以仅在不启动它们的情况下构建图像,并且最好选择构建或构建所有图像?
答案 0 :(得分:3)
您可以在不启动它们的情况下构建特定服务:
docker-compose build node1
全部构建它们:
docker-compose build
答案 1 :(得分:1)
您也可以尝试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.