-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Cli change to pass driver specific options to docker run #156
Conversation
cli/command/network/connect.go
Outdated
"github.com/docker/cli/cli" | ||
"github.com/docker/cli/cli/command" | ||
"github.com/docker/cli/opts" | ||
"github.com/docker/docker/api/types/network" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/net/context" | ||
"strings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put fmt
and strings
first in the list, then a blank line before the non-stdlib imports.
cli/command/network/connect.go
Outdated
parts := strings.SplitN(opt, "=", 2) | ||
if len(parts) != 2 { | ||
err := fmt.Errorf("invalid key value pair format in driver options") | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("invalid key/value pair format in driver options")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use errors.New("invalid key/value pair format in driver options")
, instead of fmt.Errorf()
cli/command/container/opts.go
Outdated
@@ -899,3 +921,12 @@ func validateAttach(val string) (string, error) { | |||
} | |||
return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR") | |||
} | |||
|
|||
func convertToNetworkmode(netmode opts.NetworkOpt) container.NetworkMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a NetworkMode
method to opts.NetworkOpt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful but opts.NetworkOpt is shared between services and container (docker run) and involves different conversion methods.
cli/command/container/opts.go
Outdated
networkIDOrName := "default" | ||
for _, net := range netmode.Value() { | ||
networkIDOrName = net.Target | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would instead write this as:
netOptVal := netmode.Value()
if len(netOptVal) > 0 {
networkIDOrName = netOptVal[0].Target
}
But is it correct to silently ignore everything beyond the first value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker run does not support multiple networks . if user does give multiple networks only the first network is considered.
So in the above code I decided to do the same as well to keep it in sync.
And if no network options is given then the ID would be "default"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker run does not support multiple networks . if user does give multiple networks only the first network is considered.
The reason for only supporting a single network, was that there was no way to pass options per-network (also, --network-alias
would be applied to all networks that you attached the container to) - also see moby/moby#31964, and issues linked from that.
If the API supports multiple networks on create, perhaps we should change that (can be a follow-up to this PR), as this should now be possible from a UX perspective;
docker run \
--network name=docknet,alias=web1.0,driver-opt=field1=value1 \
--network name=second-net,alias=foobar,driver-opt=hello=world \
nginx:alpine
(edit: removed --driver-opt
because there's no such thing 😄)
@abhinandanpb can you address @aaronlehmann comments? |
cli/command/network/connect.go
Outdated
return nil, err | ||
} | ||
key := strings.TrimSpace(strings.ToLower(parts[0])) | ||
value := strings.TrimSpace(strings.ToLower(parts[1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all options and values lowercase? If not needed, I'd rather not transform options that were passed by the user (in case some particular driver has options that are case sensitive)
Better to have the daemon return an error if an option is not valid
(I realize I didn't check the implementation for services, we may want to consider doing the same there)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I thought of that as well. But I saw that the other options like port were converting to lower case. So I decided to maintain the uniformity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For port we probably have more control over the available options (although I'd be in favour of moving validation to the daemon as well); for plugins/drivers we have no knowledge whatsoever what's supported.
It should be easy to add this back in future if we want, more difficult to remove ("Docker 17.07 supported opt=foObAr
and now produces an error!")
Looks like I didn't look closely at those examples, some remarks;
Would it be both |
Yes thats doable and makes sense as well. I can update the PR with the change.
yes its disallowed. And I believe we should to avoid ambiguity. |
@thaJeztah looks like it got closed because of another PR referring to it. Can you please reopen this one ? |
The commit contains cli changes to support driver options for a network in docker run and docker network connect cli's.
The driver-opt, aliases is now supported in the form of csv as per network option in service commands in swarm mode since #62 . This commit extends this support to docker run command as well.
For docker connect command --driver-opt is added to pass driver specific options for the network the container is connecting to.
Following is supported:
Signed-off-by: Abhinandan Prativadi [email protected]
cc @mavenugo