服务X从Y安装卷,而不是服务或容器的名称 [英] Service X mounts volumes from Y, which is not the name of a service or container
问题描述
使用docker-compose我试图创建一个共享卷,我的两个服务都可以使用它。我在我的 docker-compose.yml
Using docker-compose I'm attempting to create a shared volume that two of my services can both use. I have the following in my docker-compose.yml
version: '2'
volumes:
bundler:
driver: local
sidekiq:
build: .
volumes_from:
- bundler:/.bundle
web:
build: .
volumes_from:
- bundler:/.bundle
工作并给我:
错误:服务sidekiq从bundler安装卷,而不是服务或容器的名称
ERROR: Service "sidekiq" mounts volumes from "bundler", which is not the name of a service or container.
使用docker-compose做什么正确的方法?
What is the correct way of doing this using docker-compose?
推荐答案
我认为你在这里混合了两个概念。
I think you mixed two concepts here.
-
volumes_from
当一个容器有一些卷(装载或不装载)应用于存储时使用。然后,您可以通过引用所谓的data-only-container
与volumes_from
来指定一个容器或(撰写)服务名称。另一方面,
volumes_from
is used when one container has some volumes (mounted or not) that should be used for storage. You can then use this container's volumes by referencing the so calleddata-only-container
withvolumes_from
which must point to a container or (compose) service name.
卷
用于引用本地文件夹或命名卷。一个命名的卷然后必须在编译文件的顶级条目卷
中声明。
volumes
on the other hand is used to reference either a local folder or a named volume. A named volume then must be declared in the top level entry volumes
of the compose file as you already did.
所以在你的情况下,从 volumes_from
到卷
之间的切换做伎俩有关详细信息,请参阅参考文档: https://docs.docker .com / compose / compose-file /#/ volumes-volume-driver
So in your case, a switch from volumes_from
to volumes
should do the trick. Please see the reference docs for details: https://docs.docker.com/compose/compose-file/#/volumes-volume-driver
这篇关于服务X从Y安装卷,而不是服务或容器的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!