diff --git a/buildfile.go b/buildfile.go index effad01ef0..931395efec 100644 --- a/buildfile.go +++ b/buildfile.go @@ -187,9 +187,6 @@ func (b *buildFile) CmdCmd(args string) error { } func (b *buildFile) CmdExpose(args string) error { - if strings.Contains(args, ":") { - return fmt.Errorf("EXPOSE cannot be used to bind to a host ip or port") - } ports := strings.Split(args, " ") b.config.PortSpecs = append(ports, b.config.PortSpecs...) return b.commit("", b.config.Cmd, fmt.Sprintf("EXPOSE %v", ports)) @@ -433,10 +430,13 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error { } } - container, _, err := b.runtime.Create(b.config, "") + container, warnings, err := b.runtime.Create(b.config, "") if err != nil { return err } + for _, warning := range warnings { + fmt.Fprintf(b.out, " ---> [Warning] %s\n", warning) + } b.tmpContainers[container.ID] = struct{}{} fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(container.ID)) id = container.ID diff --git a/runtime.go b/runtime.go index e5c535f9fc..097a74a1f4 100644 --- a/runtime.go +++ b/runtime.go @@ -317,22 +317,20 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin return nil, nil, err } - warnings := []string{} if img.Config != nil { - if img.Config.PortSpecs != nil && warnings != nil { - for _, p := range img.Config.PortSpecs { - if strings.Contains(p, ":") { - warnings = append(warnings, "This image expects private ports to be mapped to public ports on your host. "+ - "This has been deprecated and the public mappings will not be honored."+ - "Use -p to publish the ports.") - break - } - } - } if err := MergeConfig(config, img.Config); err != nil { return nil, nil, err } } + warnings := []string{} + if config.PortSpecs != nil { + for _, p := range config.PortSpecs { + if strings.Contains(p, ":") { + warnings = append(warnings, "The mapping to a public ports on your host has been deprecated. Use -p to publish the ports.") + break + } + } + } if len(config.Entrypoint) != 0 && config.Cmd == nil { config.Cmd = []string{} diff --git a/runtime_test.go b/runtime_test.go index 5f4aa92e5a..07b641fd7e 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -260,6 +260,21 @@ func TestRuntimeCreate(t *testing.T) { if err != nil { t.Error(err) } + + // test expose 80:8000 + container, warnings, err := runtime.Create(&Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"ls", "-al"}, + PortSpecs: []string{"80:8000"}, + }, + "", + ) + if err != nil { + t.Fatal(err) + } + if warnings == nil { + t.Error("Expected a warning, got none") + } } func TestDestroy(t *testing.T) {