Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
expose published ports as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Bogdanov committed Jul 7, 2015
1 parent e9ae6d4 commit ed4dd13
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/compose/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/go-yaml/yaml"
)

// TODO: ports default to /tcp

// Config represents the data structure which is loaded from compose.yml
type Config struct {
Namespace string // All containers names under current compose.yml will be prefixed with this namespace
Expand Down Expand Up @@ -183,6 +181,13 @@ func ReadConfig(name string, reader io.Reader, vars map[string]interface{}) (*Co
container.Net.Container = *container.Net.Container.DefaultNamespace(config.Namespace)
}
}

// Fix exposed ports
for k, port := range container.Expose {
if !strings.Contains(port, "/") {
container.Expose[k] = port + "/tcp"
}
}
}

return config, nil
Expand Down
7 changes: 6 additions & 1 deletion src/compose/config/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ func (config *Container) GetApiConfig() *docker.Config {
}

// expose
if config.Expose != nil {
if len(config.Expose) > 0 || len(config.Ports) > 0 {
apiConfig.ExposedPorts = map[docker.Port]struct{}{}
for _, portBinding := range config.Expose {
port := (docker.Port)(portBinding)
apiConfig.ExposedPorts[port] = struct{}{}
}
// expose publised ports as well
for _, configPort := range config.Ports {
port := (docker.Port)(configPort.Port)
apiConfig.ExposedPorts[port] = struct{}{}
}
}

// env
Expand Down
1 change: 1 addition & 0 deletions src/compose/config/testdata/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ containers:
entrypoint: ["/bin/patterns"]
expose:
- 23456/tcp
- 5000
publish_all_ports: true
labels:
service: pattern
Expand Down
2 changes: 1 addition & 1 deletion src/compose/config/testdata/container_main_config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Hostname":"pattern1","Domainname":"grammarly.com","User":"root","Memory":314572800,"MemorySwap":1073741824,"CpuShares":512,"Cpuset":"0-2","ExposedPorts":{"23456/tcp":{}},"Env":["AWS_KEY=asdqwe"],"Cmd":["param1","param2"],"Image":"dockerhub.grammarly.io/patterns:1.9.2","Volumes":{"/var/log":{}},"WorkingDir":"/app","Entrypoint":["/bin/patterns"],"NetworkDisabled":true,"Labels":{"num":"1","service":"pattern"}}
{"Hostname":"pattern1","Domainname":"grammarly.com","User":"root","Memory":314572800,"MemorySwap":1073741824,"CpuShares":512,"Cpuset":"0-2","ExposedPorts":{"23456/tcp":{},"5000/tcp":{},"5005/tcp":{},"5006/tcp":{}},"Env":["AWS_KEY=asdqwe"],"Cmd":["param1","param2"],"Image":"dockerhub.grammarly.io/patterns:1.9.2","Volumes":{"/var/log":{}},"WorkingDir":"/app","Entrypoint":["/bin/patterns"],"NetworkDisabled":true,"Labels":{"num":"1","service":"pattern"}}

0 comments on commit ed4dd13

Please sign in to comment.