diff --git a/pkg/localnet/helpers.go b/pkg/localnet/helpers.go index b48c1e9..b108f0c 100644 --- a/pkg/localnet/helpers.go +++ b/pkg/localnet/helpers.go @@ -50,12 +50,12 @@ func PlatformDirMount(ctx context.Context, platform tools.Platform) (volume infr // FromHostAddress returns address of the app service seen from the host. func FromHostAddress(proto string, app *infra.App, port infra.PortName) string { - return infra.JoinNetAddr(proto, app.Info().HostFromHost, app.Ports[port]) + return infra.JoinNetAddr(proto, app.Info().HostFromHost, app.Ports[port].HostPort) } // FromContainerAddress returns address of the app service seen from the container. func FromContainerAddress(proto string, app *infra.App, port infra.PortName) string { - return infra.JoinNetAddr(proto, app.Info().HostFromContainer, app.Ports[port]) + return infra.JoinNetAddr(proto, app.Info().HostFromContainer, app.Ports[port].ContainerPort) } func appDir(ctx context.Context, appName string) string { diff --git a/pkg/localnet/infra/docker.go b/pkg/localnet/infra/docker.go index 0f1965e..1c0dd38 100644 --- a/pkg/localnet/infra/docker.go +++ b/pkg/localnet/infra/docker.go @@ -9,7 +9,6 @@ import ( "os" osexec "os/exec" "path/filepath" - "strconv" "strings" "sync" "time" @@ -179,8 +178,7 @@ func (d *Docker) prepareRunArgs(app *App) []string { runArgs = append(runArgs, "--user", fmt.Sprintf("%d:%d", os.Getuid(), os.Getgid())) } for _, port := range app.Ports { - portStr := strconv.Itoa(port) - runArgs = append(runArgs, "-p", "127.0.0.1:"+portStr+":"+portStr+"/tcp") + runArgs = append(runArgs, "-p", fmt.Sprintf("127.0.0.1:%d:%d/tcp", port.HostPort, port.ContainerPort)) } for _, v := range app.Volumes { runArgs = append(runArgs, "-v", lo.Must(filepath.EvalSymlinks(lo.Must(filepath.Abs(v.Source))))+":"+ diff --git a/pkg/localnet/infra/types.go b/pkg/localnet/infra/types.go index b2a4afd..b529be5 100644 --- a/pkg/localnet/infra/types.go +++ b/pkg/localnet/infra/types.go @@ -192,8 +192,14 @@ type Volume struct { // PortName represents the name of the port. type PortName string +// DockerPort is the port mapping from host to container. +type DockerPort struct { + HostPort int + ContainerPort int +} + // Ports is the map of exposed ports. -type Ports map[PortName]int +type Ports map[PortName]DockerPort // App represents application to be deployed. type App struct {