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

Allow passing allocation subnet to docker run #7436

Closed
wants to merge 5 commits into from
Closed

Allow passing allocation subnet to docker run #7436

wants to merge 5 commits into from

Conversation

phemmer
Copy link
Contributor

@phemmer phemmer commented Aug 6, 2014

This is an extension of PR #5829. This PR allows passing a range of addresses to docker run for the IP allocator to pick an address from.

Example usage:

docker run --ip 172.42.44.10 myimage
docker run --ip 172.42.44.10/32 myimage
docker run --ip 172.42.44.0/24 myimage

This obsoletes #5829 as you can pass a specific IP in addition to a subnet/range.

I haven't added anything in the way of documentation. I wanted to put this out in its current form and make requested changes first.


The purpose of this PR is for multi-tenant solutions, where you have multiple products or customers running on a docker host, and you want to be able to add firewall rules per customer. With this, when starting a customer's container, you could pass a subnet, and ensure that their container gets an IP that will be properly matched by a firewall rule or routing policy.


Related: #2801 #6743

vishh added 2 commits May 16, 2014 17:36
…er containers.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
…creates, to avoid reusing the static IPs

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
rangeFirstInt = networkFirstInt
rangeLastInt = networkLastInt
subnetAllocatedPos = allocated.last
pos = subnetAllocatedPos - (rangeFirstInt - baseInt) // relative to the start of available addresses
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed a lot of the variable names as they were extremely confusing to work with. Some of them were integers, some were IPNet, IP, etc.
I can change the names to something else if desired. Just not the originals please :-)

@LK4D4
Copy link
Contributor

LK4D4 commented Aug 6, 2014

Hi, @phemmer . I have similar PR but daemon-wide for multihost installations #6101, it needs some care about docs. There is already similar code for ranges, maybe we can collaborate with our code bases.

@phemmer
Copy link
Contributor Author

phemmer commented Aug 6, 2014

@LK4D4 I think they serve different goals, and can co-exist.
The purpose of this PR is for multi-tenant solutions, where you have multiple products or customers running on a docker host, and you want to be able to add firewall rules per customer. With this, when starting a customer's container, you could pass a subnet, and ensure that their container gets an IP that will be properly matched by a firewall rule or routing policy.

updated description to include this

@LK4D4
Copy link
Contributor

LK4D4 commented Aug 6, 2014

@phemmer, Yeah, but one of us will have pretty difficult rebase :D

@SvenDowideit
Copy link
Contributor

can you please add documentation in cli.md, the man pages and the networking document.

@phemmer
Copy link
Contributor Author

phemmer commented Aug 9, 2014

@ashahab-altiscale that's exactly as it's supposed to behave. This feature allows you to change the IPs docker picks from, not change the IP and subnet of the container. You told it it could pick from anywhere between 172.17.0.0 to 172.17.255.255, and it did.

@phemmer
Copy link
Contributor Author

phemmer commented Aug 9, 2014

@SvenDowideit Documentation added.

However the biggest uncertainty I have is the name of the parameter. Right now it's --ip, however unless people read the --help output, and understand that it's meant to be taken literally, it might be confused as for setting the IP & subnet of the container.
Some alternate names I had throught of were --ip-pool and --ip-range. But --ip is also nice and simple, and technically accurate as the name implies nothing about the subnet.

@thaJeztah
Copy link
Member

Just chiming in that, indeed, --ip might be confusing, especially since the same option for the server has a different meaning. From the same document;

--ip=IP_ADDRESS — see Binding container ports

Not sure what the best name would be though.

@ashahab-altiscale
Copy link
Contributor

Yes I realized it right after posting the comment. Great feature!

@ashahab-altiscale https://github.com/ashahab-altiscale that's exactly as
it's supposed to behave. This feature allows you to change the IPs docker
picks from, not change the IP and subnet of the container. You told it it
could pick from anywhere between 172.17.0.0 to 172.17.255.255, and it did.


Reply to this email directly or view it on GitHub
#7436 (comment).

@@ -613,6 +617,20 @@ Docker do all of the configuration:
At this point your container should be able to perform networking
operations as usual.

As mentioned briefly above, `docker run` accepts a `--ip` flag which
limits the IP pool docker will use to pick the container's IP address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker

@phemmer
Copy link
Contributor Author

phemmer commented Aug 10, 2014

@jamtur01 docker/Docker fixed

@thaJeztah
Copy link
Member

@phemmer has the decision on naming this --ip been finalised yet?

@phemmer
Copy link
Contributor Author

phemmer commented Aug 10, 2014

@thaJeztah I do not know. if that discussion has been continued somewhere besides this PR, I am unaware of it.

@thaJeztah
Copy link
Member

@phemmer ok, thnx. Think it might be slightly confusing and inconsistent (see my prior comment). But IANTM, just my personal view :). Apart from that, looks like a nice addition.

@phemmer
Copy link
Contributor Author

phemmer commented Aug 10, 2014

Well to throw in my $0.02 on the conflict with the daemon's --ip argument:

I think the daemon --ip argument is misnamed. Without reading any --help output or documentation, I would expect such an argument to set the IP of docker (the bridge addr). I think a more appropriate name would be --bind-ip or similar.

Also do we want to go down the route where no argument can share a name between the daemon and docker run unless the action is similar? The --ip case aside, I think that approach is bad.

@thaJeztah
Copy link
Member

Re-reading the option again, --ip is probably ok. My confusion was mainly caused by the =IP_RANGE. From which I gathered that only a range could be specified, but re-reading the example, I noticed that a single address is allowed as well (a single address is also a range – albeit very limited 😄).

Maybe someone has ideas to make that clearer. IP_ADDRESS | RANGE , IP_RANGE[/SIZE]. Don't have a good suggestion here.

RE: "..no argument can share a name.."
No! Sorry I gave that impression, but in this case one option allows a single ip-address, the other a range. Which supports which may become hard to remember. And I 100% agree that the other option is confusing.

Please don't let my comment block merging of this PR, nothing that cannot be improved on later on!

* commit 'a27bebc':
  Fixed ipallocator to record static IPs along with the dynamic IPs it creates, to avoid reusing the static IPs
  Adding '--ip' option to 'docker run' to let users manage IPs for docker containers.

Conflicts:
	daemon/networkdriver/ipallocator/allocator.go
	runconfig/config_test.go
	runconfig/parse.go

Docker-DCO-1.1-Signed-off-by: Patrick Hemmer <patrick.hemmer@gmail.com> (github: phemmer)
Docker-DCO-1.1-Signed-off-by: Patrick Hemmer <patrick.hemmer@gmail.com> (github: phemmer)
Docker-DCO-1.1-Signed-off-by: Patrick Hemmer <patrick.hemmer@gmail.com> (github: phemmer)
@DwayneBull
Copy link

I'm new to github, does the "all is well" status mean this will be merged to master soon?

@thaJeztah
Copy link
Member

@DwayneBull no, "all well" means that all unit-tests and integration-tests passed correctly.

In other words, the changes in this pull request didn't break anything that was working before. However, that doesn't mean that this PR will be merged soon, or even ever. The decision to merge PRs depends on the maintainers agreeing that the PR should be merged.

Just bookmark this page to keep track on progress

@DwayneBull
Copy link

Ah I see. Sorry I don't know how this all works. Thank you for the information.

@ashahab-altiscale
Copy link
Contributor

Is this under review for merge to master? I find this to be very useful.

@DwayneBull
Copy link

Given that #6101 was merged, is this still valid?

@LK4D4
Copy link
Contributor

LK4D4 commented Sep 23, 2014

@DwayneBull Yup, this is per-container option.

@DwayneBull
Copy link

@LK4D4 So ip allocation would look like this?
(container --ip) subset of (deamon --fixed-cidr) subset of (deamon --bip)

@LK4D4
Copy link
Contributor

LK4D4 commented Sep 23, 2014

@DwayneBull Yes indeed

@ashahab-altiscale
Copy link
Contributor

@phemmer , @LK4D4 , what is needed for this to be merged?

@phemmer
Copy link
Contributor Author

phemmer commented Sep 23, 2014

For a project maintainer to take interest in it.
I need to rebase it, but I don't want to keep rebasing it if it's going to be months before it's merged. So once it gets interest, I'll start keeping it maintained.

@pesho
Copy link

pesho commented Oct 21, 2014

Very much interested in this one. Any maintainer interested in reviewing it? cc @shykes

I think the daemon --ip argument is misnamed.

+1, --ip makes perfect sense as a run argument in this case (unlike the daemon argument)

if ipAddr == nil {
return job.Error(fmt.Errorf("Invalid IP: %s", requestedIP))
}
if ipAddr.To4 != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To4 is function which can't be nil. Heh, this is like python :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure it can.

http://golang.org/pkg/net/#IP.To4

If ip is not an IPv4 address, To4 returns nil.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You compare function with nil, not its result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh!

@LK4D4
Copy link
Contributor

LK4D4 commented Oct 21, 2014

I like this very much. But now it needs rewriting because of merging --fixed-cidr :(

@shykes
Copy link
Contributor

shykes commented Nov 1, 2014

Sorry for late review.

  1. All the maintainers agree that this is needed, in some form. There should be a way to configure different network ranges for different containers. The "multi-tenant product" use case you describe is totally valid.
  2. There is a general concern with mixing 2 different types of configuration in the same API. It's not unique to this PR, but reviewing this triggered a long conversation about that problem. Basically, we believe that infrastructure-specific config, like "allocate this IP range", or "use this storage driver", or "mount this directory from the host", should not be exposed over the docker API, because they violate separation of concerns. The Docker API should be used to consume infrastructure - not define it.
  3. In the case of this specific PR, your use case would be enabled by wrapping the docker client, rather than hooking it. Generally we want to encourage hooking instead of wrapping, because you can easily compose hooks, but you cannot compose wrappers.

Because of this, we are suggesting the following:

  • Don't expose this feature in the API. So, I'm afraid we're going to close this PR. Again, really sorry for coming in so late, I know you've put considerable effort in reacting to code review. FYI we are working on a better design process, so that you can get a design proposal approved first, and then send implementation, which should avoid such waste of time.
  • Instead, we really really want to make this feature available via hooks. It just so happens that we are starting work on plugins for Docker. We are going to use this use case as the 1st use case for plugins. This will be a joint effort between @erikh (who is handling various network-related improvements atm), @dmcg (who contributed the communication layer we'll use for plugins), @ibuildthecloud (wants plugins to contribute another network feature), @jfrazelle @crosbymichael @dmp42 (doing this review with me), @cpuguy83 (playing with docker+libchan).

TLDR: we're closing this but a shitload of people want to implement it in a different way, and build something very important for the project in the process. You are welcome to join the fun :)

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

Successfully merging this pull request may close these issues.

10 participants