fix: docker socket handler

This commit is contained in:
yusing 2025-05-10 11:24:28 +08:00
parent 2c0b68c8c2
commit 0208e6286f
2 changed files with 10 additions and 8 deletions

View file

@ -47,4 +47,5 @@ COPY --from=builder /app/run /app/run
WORKDIR /app
ENV LISTEN_ADDR=0.0.0.0:2375
CMD ["/app/run"]

View file

@ -9,8 +9,6 @@ import (
"time"
"github.com/gorilla/mux"
"net/url"
)
var dialer = &net.Dialer{KeepAlive: 1 * time.Second}
@ -22,12 +20,15 @@ func dialDockerSocket(ctx context.Context, _, _ string) (net.Conn, error) {
var DockerSocketHandler = dockerSocketHandler
func dockerSocketHandler() http.HandlerFunc {
rp := httputil.NewSingleHostReverseProxy(&url.URL{
Scheme: "http",
Host: "api.moby.localhost",
})
rp.Transport = &http.Transport{
DialContext: dialDockerSocket,
rp := &httputil.ReverseProxy{
Director: func(req *http.Request) {
req.URL.Scheme = "http"
req.URL.Host = "api.moby.localhost"
req.RequestURI = req.URL.String()
},
Transport: &http.Transport{
DialContext: dialDockerSocket,
},
}
return rp.ServeHTTP