Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -722,6 +722,20 @@ func TestLoopbackWhenNetworkDisabled(t *testing.T) {
|
| 722 | 722 |
logDone("run - test container loopback when networking disabled")
|
| 723 | 723 |
} |
| 724 | 724 |
|
| 725 |
+func TestNetHostNotAllowedWithLinks(t *testing.T) {
|
|
| 726 |
+ _, _, err := cmd(t, "run", "--name", "linked", "busybox", "true") |
|
| 727 |
+ |
|
| 728 |
+ cmd := exec.Command(dockerBinary, "run", "--net=host", "--link", "linked:linked", "busybox", "true") |
|
| 729 |
+ _, _, err = runCommandWithOutput(cmd) |
|
| 730 |
+ if err == nil {
|
|
| 731 |
+ t.Fatal("Expected error")
|
|
| 732 |
+ } |
|
| 733 |
+ |
|
| 734 |
+ deleteAllContainers() |
|
| 735 |
+ |
|
| 736 |
+ logDone("run - don't allow --net=host to be used with links")
|
|
| 737 |
+} |
|
| 738 |
+ |
|
| 725 | 739 |
func TestLoopbackOnlyExistsWhenNetworkingDisabled(t *testing.T) {
|
| 726 | 740 |
cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up") |
| 727 | 741 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -15,10 +15,11 @@ import ( |
| 15 | 15 |
) |
| 16 | 16 |
|
| 17 | 17 |
var ( |
| 18 |
- ErrInvalidWorkingDirectory = fmt.Errorf("The working directory is invalid. It needs to be an absolute path.")
|
|
| 19 |
- ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d")
|
|
| 20 |
- ErrConflictDetachAutoRemove = fmt.Errorf("Conflicting options: --rm and -d")
|
|
| 21 |
- ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: -h and the network mode (--net)")
|
|
| 18 |
+ ErrInvalidWorkingDirectory = fmt.Errorf("The working directory is invalid. It needs to be an absolute path.")
|
|
| 19 |
+ ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d")
|
|
| 20 |
+ ErrConflictDetachAutoRemove = fmt.Errorf("Conflicting options: --rm and -d")
|
|
| 21 |
+ ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: -h and the network mode (--net)")
|
|
| 22 |
+ ErrConflictHostNetworkAndLinks = fmt.Errorf("Conflicting options: --net=host can't be used with links. This would result in undefined behavior.")
|
|
| 22 | 23 |
) |
| 23 | 24 |
|
| 24 | 25 |
//FIXME Only used in tests |
| ... | ... |
@@ -115,6 +116,10 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf |
| 115 | 115 |
return nil, nil, cmd, ErrConflictNetworkHostname |
| 116 | 116 |
} |
| 117 | 117 |
|
| 118 |
+ if *flNetMode == "host" && flLinks.Len() > 0 {
|
|
| 119 |
+ return nil, nil, cmd, ErrConflictHostNetworkAndLinks |
|
| 120 |
+ } |
|
| 121 |
+ |
|
| 118 | 122 |
// If neither -d or -a are set, attach to everything by default |
| 119 | 123 |
if flAttach.Len() == 0 && !*flDetach {
|
| 120 | 124 |
if !*flDetach {
|