Docker组成重用卷 [英] Docker compose reusing volumes

查看:86
本文介绍了Docker组成重用卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个新的Docker映像,该映像不再使用正在运行的使用映像的容器中的卷。这些卷是使用docker-compose文件而非Dockerfile创建的。问题是,当我通过新的docker-compose.yml文件启动新容器时,它仍然具有映射的卷。我仍然需要保留这些卷以及使用它们的原始容器/图像。另外,如果可能的话,我想继续使用相同的docker映像,只需添加一个新版本或:latest。这是我使用的步骤:



现有图像的新版本:

  docker commit< image id> existingImage:new-version 

从当前运行的容器中创建新图像:

  docker commit<图片ID> newimage 

创建未定义卷的新docker-compose.yml并使用其他项目运行docker-compose名称

  docker-compose -p<新项目名称> 

在没有docker-compose的情况下运行,只需使用docker run:

  docker run -d -p 8093:80< img>:< version> 

每次运行这些组合时,仍然会从原始映像映射这些卷。所以我的问题是,如何从曾经映射过卷但不再使用卷的映像中创建一个容器?<​​/ p>

编辑:
我尝试过的其他操作:




  • 停止容器,删除容器,重新启动docker,再次运行docker compose。没有运气。



编辑2:
决定从图像上重新开始。使用基本映像,启动一个容器,该容器具有使用现在不相关的映像的更新的docker compose文件。运行docker-compose -f up -d-> STILL会映射这些相同的卷,即使映像没有(也从来没有)映射任何卷,并且当前docker-compose.yml文件未映射文件。看起来docker-compose缓存了为项目映射的卷。



在docker-compose中搜索缓存选项后,我遇到了这篇文章:如何获取docker-compose以始终重新创建
似乎解决了缓存图像而不是容器缓存卷的问题

解决方案

根据另一篇SO帖子,我要做的事情是不可能的。为了将来参考,无法将卷附加到映像,然后再决定将其删除。必须创建不包含卷的新映像。参考:
如何在Docker映像中删除配置卷


I'm trying to create a new Docker image that no longer uses volumes from a running container that does use images. The volumes were created using docker-compose file, not Dockerfile. The problem is, when I launch a new container via new docker-compose.yml file it still has the volumes mapped. I still need to keep these volumes and the original containers/images that use them. Also, if possible I would like to continue to use the same docker image, just add a new version, or :latest. Here's the steps I used:

New version of an existing image:

docker commit <image id> existingImage:new-version

Create a new image from current running container:

docker commit <Image ID> newimage

Create new docker-compose.yml with no volumes defined and run docker-compose with a different project name

docker-compose -p <new project name> 

Running without docker-compose, just use docker run:

 docker run -d -p 8093:80 <img>:<version>

Any time I run any combination of these the volumes are still mapped from the original image. So my question is, how to I create a container from an image that once had mapped volumes but I no longer want to use the volumes?

Edit: Additional things I've tried:

  • Stop container, remove container, restart docker, run docker compose again. No luck.

Edit 2: Decided to start over on the image. Using a base image, launched a container with an updated docker compose file that uses the now unrelated image. Run docker-compose -f up -d -> STILL has these same volumes mapped even though the image does not (and never has) any volumes mapped, and the current docker-compose.yml file does not map files. It looks like docker-compose caches what volumes are mapped for projects.

After searching for caching options in docker-compose, I came across this article: How to get docker-compose to always re-create containers from fresh images? which seems to solve the problem of caching images but not containers caching volumes

解决方案

According to another SO post what I am trying to do is not possible. For future reference, one cannot attach volumes to an image, and then later decide to remove them. A new image must be created without the volumes instead. Reference: How to remove configure volumes in docker images

这篇关于Docker组成重用卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆