MCPcopy
hub / github.com/docker/compose / buildContainerPorts

Function buildContainerPorts

pkg/compose/create.go:801–827  ·  view source on GitHub ↗
(s types.ServiceConfig)

Source from the content-addressed store, hash-verified

799}
800
801func buildContainerPorts(s types.ServiceConfig) (network.PortSet, error) {
802 // Add published ports as exposed ports.
803 exposedPorts := network.PortSet{}
804 for _, p := range s.Ports {
805 np, err := network.ParsePort(fmt.Sprintf("%d/%s", p.Target, p.Protocol))
806 if err != nil {
807 return nil, err
808 }
809 exposedPorts[np] = struct{}{}
810 }
811
812 // Merge in exposed ports to the map of published ports
813 for _, e := range s.Expose {
814 // support two formats for expose, original format <portnum>/[<proto>]
815 // or <startport-endport>/[<proto>]
816 pr, err := network.ParsePortRange(e)
817 if err != nil {
818 return nil, err
819 }
820 // parse the start and end port and create a sequence of ports to expose
821 // if expose a port, the start and end port are the same
822 for p := range pr.All() {
823 exposedPorts[p] = struct{}{}
824 }
825 }
826 return exposedPorts, nil
827}
828
829func buildContainerPortBindingOptions(s types.ServiceConfig) (network.PortMap, error) {
830 bindings := network.PortMap{}

Callers 1

getCreateConfigsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected