重新安装孤立的码头卷 [英] Reattaching orphaned docker volumes
问题描述
FROM base-image
VOLUME / path / to / something
RUN do_stuff
....
当我运行容器时,它创建一个卷 VolumeA ),当我执行 docker volume ls
时,我可以看到。
如果我停止并移除容器,那么<em> VolumeA 将按预期的方式进行。
我的问题是,如果我运行新版本的容器,有没有办法使用 VolumeA ,而不是创建一个新的一?
我更喜欢使用命名卷,因为您可以轻松地将它们挂载到新的容器。
但是对于未命名的卷,我:
- 运行我的容器(VOLUME指令使它创建一个新卷通过检查可以获得的新路径)
- 将旧卷的路径移动到该新路径。
之前 docker volume命令,我曾经这样做与 a script : updateDataContainerPath.sh
。
但是,这些天,我的图片都没有一个 VOLUME
:我创建单独命名的卷( docker volume create
),并在运行时挂载到容器( docker run -v my-named-volume:/ my / path
)
I'm using a docker volume, specified in my dockerfile so that my data can persist on the host. The dockerfile looks something like this:
FROM base-image
VOLUME /path/to/something
RUN do_stuff
....
When I run the container it creates a volume (call it VolumeA) which I can see when I do a docker volume ls
.
If I stop and remove the container, the VolumeA sticks around as expected.
My question is, if I run a new version of the container, is there a way to use VolumeA rather than have it create a new one?
I prefer using named volumes, as you can mount them easily to a new container.
But for unnamed volume, I:
- run my container (the VOLUME directive causes it to create a new volume to a new path that you can get by inspecting it)
- move the path of the old volume to that new path.
Before docker volume commands, I used to do that with a script: updateDataContainerPath.sh
.
But again, these days, none of my images have a VOLUME
in them: I create separately named volumes (docker volume create
), and mount them to containers at runtime (docker run -v my-named-volume:/my/path
)
这篇关于重新安装孤立的码头卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!