Using docker-compose I'm attempting to create a shared volume that 2 of my services can both utilise. I have the following in my docker-compose.yml

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

This however doesn't work and gives me:

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

What is the right fashion of doing this using docker-compose?

asked Aug 16, 2016 at xx:49

user avatar

0

4 Answers 4

I think yous mixed two concepts hither.

  • volumes_from is used when one container has some volumes (mounted or not) that should be used for storage. Yous can then use this container's volumes by referencing the so called data-simply-container with volumes_from which must indicate to a container or (etch) service name.

  • volumes on the other mitt is used to reference either a local folder or a named volume. A named volume so must be declared in the elevation level entry volumes of the compose file equally you already did.

And then in your instance, a switch from volumes_from to volumes should do the trick. Please see the reference docs for details: https://docs.docker.com/compose/etch-file/#/volumes-volume-driver

answered Aug 16, 2016 at 21:26

user avatar

1

  • this is a perfect and detailed explanation and the theory backside my suggestion for the answer above. We should have combined both for a expert respond :)

    Aug xvi, 2016 at 21:38

The reply should be

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

So sidekiq is you then called data-container, exposing and creating the bundler volume. Then you mountain this volume in all other containers yous need information technology, in your case for at present web. Hope this helps

answered Aug 16, 2016 at 21:21

user avatar

half dozen

  • sidekiq isn't actually the traditional definition of a information-container since it's mounting it's data from a named volume. Since your data is in a named volume, calculation the actress dependency on sidekiq to be running is adding an unnecessary dependency between the two services. In other words, with this pattern, you can't upgrade sidekiq without destroying and afterward recreating the spider web container.

    Aug 17, 2016 at ane:14

  • Intersting point. Spider web is mounting using the containter syntax, not the book syntax, thus its dependency goes to the container. If i stop all containers, then i should be able to remove sidekiq / upgrade sidekiq, correct(?) Beside that, upgrading sidekiq would non make sense in practical righti, since its a cogniteev/echo anyway, right? Exercise you heed explaining your thoughts more detailed?

    Aug 17, 2016 at 6:16

  • If you end all containers, you can upgrade sidekiq. But if you lot utilise a named book instead of a container volume, you lot can upgrade sidekiq without needing to stop spider web (see the respond I posted for how to do that). That decouples the dependencies between each container and makes them independently upgradeable. They each still have identical access to the data.

    Aug 17, 2016 at 12:37

  • i tried that - and yous do not demand to stop web when you desire to upgrade sidekiq. You lot stop sidekiq, rm it, upgrade it and start it again, reusing the same volume. Web does not need to be stopped during

    Aug 17, 2016 at 15:43

  • Now try stopping them both and restarting just the web container. You'll find that information technology forces you to outset the sidekiq container.

    Aug 17, 2016 at 17:11

The "volumes_from" references a container. Since you're using a named book, yous 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 demand to specify services in their own services: department instead of the superlative level of the yml.

answered Aug 16, 2016 at 21:17

user avatar

If you actually desire to utilize volumes_from with a container(data only), use

                volumes_from:  - container:"yourdataonlycontainer"                              

answered May x, 2018 at 17:49

user avatar

Not the reply you're looking for? Browse other questions tagged docker docker-compose or inquire your own question.