Service X mounts volumes from Y, which is not the name of a service or container

纵饮孤独 提交于 2020-01-06 03:37:23

问题


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

This however doesn't work and gives me:

ERROR: Service "sidekiq" mounts volumes from "bundler", which is not the name of a service or container.

What is the correct way of doing this using docker-compose?


回答1:


I think you mixed two concepts here.

  • 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 called data-only-container with volumes_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.

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




回答2:


The answer should be

version: '2'
volumes:
  bundler:
    driver: local
sidekiq:
  build: .
  volumes:
    - bundler:/.bundle
web:
  build: .
  volumes_from:
    - sidekiq:rw

So sidekiq is you so called data-container, exposing and creating the bundler volume. Then you mount this volume in all other containers you need it, in your case for now web. Hope this helps




回答3:


The "volumes_from" references a container. Since you're using a named volume, you need "volumes":

version: '2'
volumes:
  bundler:
    driver: local
services:
  sidekiq:
    build: .
    volumes:
      - bundler:/.bundle
  web:
    build: .
    volumes:
      - bundler:/.bundle

Also, since you're using version 2, you need to specify services in their own services: section instead of the top level of the yml.




回答4:


If you really want to use volumes_from with a container(data only), use

volumes_from:
 - container:"yourdataonlycontainer"


来源:https://stackoverflow.com/questions/38984226/service-x-mounts-volumes-from-y-which-is-not-the-name-of-a-service-or-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!