mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Add ports publishing to run
This commit is contained in:
parent
5aa31b6bf5
commit
a1a5e1794b
@ -94,10 +94,18 @@ func (cs *containerService) List(ctx context.Context) ([]containers.Container, e
|
|||||||
func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error {
|
func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error {
|
||||||
var project compose.Project
|
var project compose.Project
|
||||||
project.Name = r.ID
|
project.Name = r.ID
|
||||||
|
var ports []types.ServicePortConfig
|
||||||
|
for _, p := range r.Ports {
|
||||||
|
ports = append(ports, types.ServicePortConfig{
|
||||||
|
Target: p.Destination,
|
||||||
|
Published: p.Source,
|
||||||
|
})
|
||||||
|
}
|
||||||
project.Services = []types.ServiceConfig{
|
project.Services = []types.ServiceConfig{
|
||||||
{
|
{
|
||||||
Name: r.ID,
|
Name: r.ID,
|
||||||
Image: r.Image,
|
Image: r.Image,
|
||||||
|
Ports: ports,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/api/containers"
|
"github.com/docker/api/containers"
|
||||||
@ -16,9 +17,18 @@ func toPorts(ports []string) ([]containers.Port, error) {
|
|||||||
|
|
||||||
for _, port := range ports {
|
for _, port := range ports {
|
||||||
parts := strings.Split(port, ":")
|
parts := strings.Split(port, ":")
|
||||||
|
source, err := strconv.ParseUint(parts[0], 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
destination, err := strconv.ParseUint(parts[1], 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
result = append(result, containers.Port{
|
result = append(result, containers.Port{
|
||||||
Source: parts[0],
|
Source: uint32(source),
|
||||||
Destination: parts[1],
|
Destination: uint32(destination),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
@ -18,8 +18,8 @@ type Container struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Port struct {
|
type Port struct {
|
||||||
Source string
|
Source uint32
|
||||||
Destination string
|
Destination uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContainerConfig struct {
|
type ContainerConfig struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user