continue build on expose with :, but displays a warning

This commit is contained in:
Victor Vieux 2013-10-30 11:13:10 -07:00
parent bb662bc12c
commit b2503a72f1
3 changed files with 28 additions and 15 deletions

View File

@ -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

View File

@ -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{}

View File

@ -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) {