Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Make net and volumes_from's container/service support explicit #2501

Closed
aanand opened this issue Dec 4, 2015 · 5 comments
Closed
Assignees
Milestone

Comments

@aanand
Copy link

aanand commented Dec 4, 2015

Right now, you can put both service and container names in volumes_from:

db:
  image: postgres
  volumes_from: ["data", "something-else"]

data:
  image: tianon/true
  volumes: ["/var/lib/postgresql/data"]

Compose will interpret the data entry in volumes_from as referring to the data service, and the something-else entry as referring to an already-created container.

The same is true of net: you can type net: "container:<container-name>" or net: "container:<service-name>".

This is error-prone: if you mistype a service name, you'll get an error saying that no such container exists, which is misleading. Furthermore, it makes it harder to tell what's going on for someone who's not aware that you can mix container and service names.

We should make the distinction explicit.

net

In the case of net, I think net: "container:<service-name>" should become net: "service:<service-name>". Both uses of net are uncommon, so we needn't make them especially concise.

volumes_from

In the case of volumes_from, it's less obvious what to do:

  1. We could rule that container and service names must be prefixed with container: or service:.
  2. We could rule that container names must be prefixed with container:, and un-prefixed names are assumed to be service names. This is probably how most people use volumes_from, so it makes sense to make the default case more concise.
  3. We could rule the opposite way: service names must be prefixed with service:, and un-prefixed names are assumed to be container names. This means that the container name case maps to the Docker CLI's --volumes-from=container-name flag, but also means that most users will have to do more typing.

I personally like option 2 best.

@aanand aanand added this to the 1.6.0 milestone Dec 4, 2015
@aanand
Copy link
Author

aanand commented Dec 4, 2015

One other solution I forgot to mention: similar to how we have two separate config keys - links and external_links - for defining links to locally-defined services versus externally-created containers, we could do something similar and have volumes_from and external_volumes_from.

@dnephin
Copy link

dnephin commented Dec 4, 2015

I also like option 2

@aanand
Copy link
Author

aanand commented Jan 14, 2016

This can now be closed:

  • Make volumes from more explicit in V2 config format #2649 sorted out volumes_from
  • --net container:... makes little sense in a post-networking (Compose file v2) world, and changing it for pre-networking (Compose file v1) would break backwards compatibility, so there's nothing to do here.

@aanand aanand closed this as completed Jan 14, 2016
@funkytaco
Copy link

Can somebody explain the documentation on this?

https://docs.docker.com/compose/compose-file/ says:

net
Networking mode. Use the same values as the docker client --net parameter.

net: "bridge"
net: "none"
net: "container:[name or id]"
net: "host"

So in my app's docker-compose YAML file, I was trying net: "container:dns" (because I want them on the same network as my dns container, but I get an error: ERROR: 409 Conflict: Conflicting options: hostname and the network mode

Are you guys saying this shouldn't be in the documentation?

@dnephin
Copy link

dnephin commented Jan 26, 2016

The documentation isn't published yet for 1.6.

The problem you're hitting isn't related. Those options are not compatible. Using the network stack from a container means it uses the hostname from the container, so you can't try setting it to something else.

Services will join the same network by default in compose 1.6, and in 1.5 with --x-networking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants