Compose: "docker-compose run" should support `--volumes-from`

Created on 27 Jul 2015  路  20Comments  路  Source: docker/compose

Would be nice if docker-compose run supported all docker run features like --volumes-from.

E.g. I have a service defined in my docker-compose.yml that can backup a file system. I want to use it with arbitrary containers, not a static list of containers specified in docker-compose.yml's volumes_from.

$ docker-compose --version
docker-compose version: 1.3.2

Sorry this might be a dup of https://github.com/docker/compose/issues/136, but that issue got closed with a fix that doesn't seem to affect docker-compose run.

arerun kinparity stale

Most helpful comment

I filed this originally, I know volumes: and volumes_from: are supported in docker-compose.yml, but I want to be able to specify volumes in individual runs, e.g.
docker-compose run -v ~/Pictures:/Pictures mybackupservice /Pictures s3://mybackup/Pictures
I guess if issue #363 covers this, this bug can be closed as a dup.

All 20 comments

+1
Having compose able to execute the whole set of docker run options is fundamental to be able to reproduce the same things done by hand but using the docker-compose.yml

:+1: Just banged my head against the wall because of this for the better part of an hour.

Editing my last post, looks like what I needed was already in the docs

https://docs.docker.com/compose/yml/#volumes_from

+1
I would like to see volumes as well as volumes-from

is it possible to create a new data volume for every new service you spin up?

For examples, I would like docker-compose to spin up 5 haproxy containers, one for each node in my docker swarm. Then I would like each one to attach to it's own data container.

@johnjelinek yeah, but the only way I know of doing that is creating five different services is docker-compose.yml with different volume paths.

@christianbundy: why different volume paths? It seems that each data container should be able to handle the same path, right? Just different data in each data container.

Sorry, I meant different volume paths on the host, not different volume paths in the container. If you used the same volume paths on the host they'd end up sharing data.

how would they share data? I only want one data container mount per haproxy container.

I just ran into this limitation. I expected docker-compose run to allow us to define volumes to mount, just as docker run does.

You can use environment variables in docker-compose.yml to achieve the same effect.

docker-compose.yml:

bar:
  image: ubuntu:trusty
  volumes:
    - /tmp
  command: ["touch", "/tmp/baz"]

foo:
  image: ubuntu:trusty
  volumes_from:
    - "$VOLUMES_FROM"

Then:

$ export VOLUMES_FROM=bar
$ docker-compose up bar
$ docker-compose run --rm foo ls -al /tmp
total 8
drwxrwxrwx  2 root root 4096 Feb  2 04:33 .
drwxr-xr-x 32 root root 4096 Feb  2 04:34 ..
-rw-r--r--  1 root root    0 Feb  2 04:33 baz

@dobbs I actually use this technique too but it gets tedious. You also need to either document it for others, or wrap it in a script.

docker compose 1.10 will bring in some nice improvements. We'll be able to define volumes and networks in the compose file itself. I'm not sure if the volumes_from will be allowed as a param though. Just three more days to wait.

docker compose 1.10 will bring in some nice improvements. We'll be able to define volumes and networks in the compose file itself. I'm not sure if the volumes_from will be allowed as a param though. Just three more days to wait.

It won't - --volumes-from as a parameter to docker-compose run has not been implemented. I've added this to the #363 meta-issue.

By the way, you can find out what to expect from the next release by looking at the release candidates' changelogs:

https://github.com/docker/compose/releases

I'd love to see this implemented - the workaround are just so hacky!

I filed this originally, I know volumes: and volumes_from: are supported in docker-compose.yml, but I want to be able to specify volumes in individual runs, e.g.
docker-compose run -v ~/Pictures:/Pictures mybackupservice /Pictures s3://mybackup/Pictures
I guess if issue #363 covers this, this bug can be closed as a dup.

+1

In case the volumes_from should be optional a workaround is to split the docker compose file in to two:

# docker-compose.yml
version: '2.0'
services:
  foo:
    image: bash
    command: "mount"
# docker-compose.vol.yml
version: '2.0'
services:
  foo:
    volumes_from:
      - container:$CONTAINER_ID
# without volumes
docker-compose run --rm foo
# with volumes from other container
CONTAINER_ID=1234567890ab docker-compose -f docker-compose.yml -f docker-compose.vol.yml run --rm foo

Any updates on this? Or any known blockers to merging #5774 ?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because it had not recent activity during the stale period.

Was this page helpful?
0 / 5 - 0 ratings