diff --git a/bin/go-proxy b/bin/go-proxy index 1bfacbb..ef91740 100755 Binary files a/bin/go-proxy and b/bin/go-proxy differ diff --git a/go.mod b/go.mod index 4baffcf..8d288b5 100755 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/yusing/go-proxy go 1.21.7 -require github.com/docker/docker v25.0.3+incompatible +require github.com/docker/docker v25.0.4+incompatible require github.com/golang/glog v1.2.0 diff --git a/go.sum b/go.sum index 0076af9..9f1defa 100755 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ= github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v25.0.4+incompatible h1:XITZTrq+52tZyZxUOtFIahUf3aH367FLxJzt9vZeAF8= +github.com/docker/docker v25.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= diff --git a/src/go-proxy/docker.go b/src/go-proxy/docker.go index 2581420..2c33c53 100755 --- a/src/go-proxy/docker.go +++ b/src/go-proxy/docker.go @@ -16,6 +16,7 @@ import ( ) var dockerClient *client.Client +var defaultHost = os.Getenv("DEFAULT_HOST") func buildContainerRoute(container types.Container) { var aliases []string @@ -44,7 +45,12 @@ func buildContainerRoute(container types.Container) { prop.Set(reflect.ValueOf(value)) } } - if config.Port == "" { + if config.Port == "" && defaultHost != "" { + for _, port := range container.Ports { + config.Port = fmt.Sprintf("%d", port.PublicPort) + break + } + } else if config.Port == "" { // usually the smaller port is the http one // so make it the last one to be set (if 80 or 8080 are not exposed) sort.Slice(container.Ports, func(i, j int) bool { @@ -87,6 +93,8 @@ func buildContainerRoute(container types.Container) { } if config.Host == "" { switch { + case defaultHost != "": + config.Host = defaultHost case container.HostConfig.NetworkMode == "host": config.Host = "host.docker.internal" case config.LoadBalance == "true":