I have multiple microservices and I am using docker-compose for development deployments. When there are some changes in the microservices code base, I am triggering ci job to re-deploy them. I have below script to do this. But each time I have to build all images from scratch, then run them. After all of this operation, I have anonymous images. So I am using the last script to remove them. What you would suggest making this process more practical? Is there any way to update an existing image without removing it with new changes?

- docker-compose build
- docker-compose down
- docker-compose up -d --force-recreate
- docker rmi $(docker images -f "dangling=true" -q) -f

附加信息:我正在使用gitlab-ci


当前回答

我已经注意到了上面的答案,但是我仍然坚持使用下面的顺序来确保一切正确:

docker-compose拉 docker-compose下来 Docker-compose up -d

其他回答

Docker容器的设计是短暂的。要更新现有容器,需要删除旧容器并启动一个新容器。 因此,您所遵循的过程是正确的。

您可以将命令简化为以下命令:

docker-compose up --force-recreate --build -d
docker image prune -f

我已经注意到了上面的答案,但是我仍然坚持使用下面的顺序来确保一切正确:

docker-compose拉 docker-compose下来 Docker-compose up -d

使用docker-compose版本3,你可以添加标签到你的图像,并根据你的逻辑清理它们:

build: ./dir
image: yourapp:tag

它可以帮助你避免匿名图像的清理

我更倾向于确保在用新图像更新容器之前下载所有图像,以最大限度地减少处于中间状态的时间,或者在图像下载失败的情况下处于中间状态的时间。

我调出了最新的图片: docker-compose拉 然后重新启动容器: Docker-compose up -d——remove-orphans 可选地,我删除过时的图像: Docker映像修剪

docker-compose pull

then

docker-compose up -d

你不需要“down”“docker-compose up -d”命令只会重新创建修改后的docker