Browse code

deny net host + dns and links with container net

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/07/30 23:51:28
Showing 1 changed files
... ...
@@ -19,8 +19,11 @@ import (
19 19
 var (
20 20
 	ErrInvalidWorkingDirectory            = fmt.Errorf("The working directory is invalid. It needs to be an absolute path.")
21 21
 	ErrConflictAttachDetach               = fmt.Errorf("Conflicting options: -a and -d")
22
+	ErrConflictContainerNetworkAndLinks   = fmt.Errorf("Conflicting options: --net=container can't be used with links. This would result in undefined behavior.")
23
+	ErrConflictContainerNetworkAndDns     = fmt.Errorf("Conflicting options: --net=container can't be used with --dns. This configuration is invalid.")
22 24
 	ErrConflictDetachAutoRemove           = fmt.Errorf("Conflicting options: --rm and -d")
23 25
 	ErrConflictNetworkHostname            = fmt.Errorf("Conflicting options: -h and the network mode (--net)")
26
+	ErrConflictHostNetworkAndDns          = fmt.Errorf("Conflicting options: --net=host can't be used with --dns. This configuration is invalid.")
24 27
 	ErrConflictHostNetworkAndLinks        = fmt.Errorf("Conflicting options: --net=host can't be used with links. This would result in undefined behavior.")
25 28
 	ErrConflictRestartPolicyAndAutoRemove = fmt.Errorf("Conflicting options: --restart and --rm")
26 29
 )
... ...
@@ -124,6 +127,18 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
124 124
 		return nil, nil, cmd, ErrConflictHostNetworkAndLinks
125 125
 	}
126 126
 
127
+	if *flNetMode == "container" && flLinks.Len() > 0 {
128
+		return nil, nil, cmd, ErrConflictContainerNetworkAndLinks
129
+	}
130
+
131
+	if *flNetMode == "host" && flDns.Len() > 0 {
132
+		return nil, nil, cmd, ErrConflictHostNetworkAndDns
133
+	}
134
+
135
+	if *flNetMode == "container" && flDns.Len() > 0 {
136
+		return nil, nil, cmd, ErrConflictContainerNetworkAndDns
137
+	}
138
+
127 139
 	// If neither -d or -a are set, attach to everything by default
128 140
 	if flAttach.Len() == 0 && !*flDetach {
129 141
 		if !*flDetach {