如果有人能做到这一点会很有用docker-compose build service1 service2 --no-cache
刚刚意识到语法是docker-compose build --no-cache service1 service2
我在找这个!!
这是我重建撰写堆栈的干净方法
cd(到您的撰写目录)
docker-compose rm --all &&
docker-compose pull &&
docker-compose build --no-cache &&
docker-compose up -d --force-recreate &&
有道理? 我在这里寻找最佳实践:)
+1
是否需要 --force-recreate ?
+1
我认为--force-recreate
是最好的选择
--force-recreate
是不必要的,因为所有容器都刚刚被移除。
如果要清除 _everything_ , down
比rm
更好,因为它还可以删除卷和网络。
$ docker-compose down -h
Stops containers and removes containers, networks, volumes, and images
created by `up`.
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the `networks` section of the Compose file
- The default network, if one is used
Networks and volumes defined as `external` are never removed.
Usage: down [options]
Options:
--rmi type Remove images. Type must be one of:
'all': Remove all images used by any service.
'local': Remove only images that don't have a custom tag
set by the `image` field.
-v, --volumes Remove named volumes declared in the `volumes` section
of the Compose file and anonymous volumes
attached to containers.
--remove-orphans Remove containers for services not defined in the
Compose file
我从 3 个月以来一直在使用它,它对于我的需求来说是坚如磐石的。
我不想删除:网络、卷和图像
echo && echo "PikWi says: docker-compose stop" && \
docker-compose stop && \
echo "PikWi says: docker-compose rm ..." && \
docker-compose rm -f --all && \
echo "PikWi says: docker-compose pull" && \
docker-compose pull && \
echo "PikWi says: docker-compose build ..." && \
docker-compose build --no-cache && \
echo "PikWi says: docker-compose up ..." && \
docker-compose up -d --force-recreate --remove-orphans
我会很高兴使用更短或更清洁的东西。 我都是最佳实践:)
干杯!
--no-cache 不起作用....有什么替代方法 --force-rebuild 继续使用缓存:(
@julianfrank不确定您所说的--no-cache does not work
是什么意思,但也许您将其运行为docker-compose build SERVICE_NAME --no-cache
当它实际上必须是docker-compose build --no-cache SERVICE_NAME
?
当构建的不同服务的步骤相同时,它仍然使用脚本中刚刚构建的容器中的缓存...当我想使用缓存并更改顺序以强制跳过缓存时,制定了使用相同步骤的替代方法用法...
如果你被缓存搞砸了,而不是不使用缓存,你在 docker 文件中插入新命令以强制更新缓存层发送竖起大拇指,docker 中的缓存处理需要重构......或者真正清理缓存层
确实,它不起作用...
您可以对服务的 Dockerfile 进行所有更改,并且docker-compose build --no-cache
上没有反射
docker-compose up -d --build --no-deps web
将为您的 docker-compose.yml 中名为“web”的服务重建容器。 重建完成后,它将重新启动指定的容器。
--no-deps
将重建限制为命令中指定的服务名称。
此外,如果您将文件复制到容器中并且您复制的文件之一已更改,则此命令将重建容器 - 例如 requirements.txt
供参考docker-compose up --force-recreate --build
up 命令显然没有 --no-cache 选项
看起来 force-recreate 不使用此选项。 如果我错了,请纠正我!
所以最好的方法是我这样做......
删除容器和图像 > 在没有构建缓存的情况下构建图像 > docker-compose up detached > 按照日志(所以你可以ctrl+c
出来)
docker-compose build --force-rm --no-cache && docker-compose up --detach && docker-compose logs -f
视窗:
docker-compose build --force-rm --no-cache ; docker-compose up --detach ; docker-compose logs -f
最有用的评论
刚刚意识到语法是
docker-compose build --no-cache service1 service2