mirror of
https://github.com/docker/cli.git
synced 2026-09-04 02:24:44 -05:00
Allocate daemon listening ports
Mark the daemon listening ports as allocated in the portallocator in order to prevent containers from exposing this port themselves. Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com> Upstream-commit: 7c225333f22378e380309bd0c3afc1b3311b1373 Component: engine
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -284,3 +285,33 @@ func TestDaemonLoggingLevel(t *testing.T) {
|
||||
|
||||
logDone("daemon - Logging Level")
|
||||
}
|
||||
|
||||
func TestDaemonAllocatesListeningPort(t *testing.T) {
|
||||
listeningPorts := [][]string{
|
||||
{"0.0.0.0", "0.0.0.0", "5678"},
|
||||
{"127.0.0.1", "127.0.0.1", "1234"},
|
||||
{"localhost", "127.0.0.1", "1235"},
|
||||
}
|
||||
|
||||
cmdArgs := []string{}
|
||||
for _, hostDirective := range listeningPorts {
|
||||
cmdArgs = append(cmdArgs, "--host", fmt.Sprintf("tcp://%s:%s", hostDirective[0], hostDirective[2]))
|
||||
}
|
||||
|
||||
d := NewDaemon(t)
|
||||
if err := d.StartWithBusybox(cmdArgs...); err != nil {
|
||||
t.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
}
|
||||
defer d.Stop()
|
||||
|
||||
for _, hostDirective := range listeningPorts {
|
||||
output, err := d.Cmd("run", "-p", fmt.Sprintf("%s:%s:80", hostDirective[1], hostDirective[2]), "busybox", "true")
|
||||
if err == nil {
|
||||
t.Fatalf("Container should not start, expected port already allocated error: %q", output)
|
||||
} else if !strings.Contains(output, "port is already allocated") {
|
||||
t.Fatalf("Expected port is already allocated error: %q", output)
|
||||
}
|
||||
}
|
||||
|
||||
logDone("daemon - daemon listening port is allocated")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user