Files
nginx-ui/internal/docker/docker.go
Jacky bfc1b21457 fix(docker): explicitly negotiate API version to ensure compatibility (#1543)
The Docker client SDK v28.5.2 defaults to API version 1.51, which may not
be supported by older Docker daemon versions. Although WithAPIVersionNegotiation()
is used, the manual Ping() call in initClient() does not trigger the automatic
version negotiation flow.

This fix explicitly calls NegotiateAPIVersionPing() with the ping response
to ensure the client uses a compatible API version with the Docker daemon.
This resolves the '404 Not Found for API route and version' error when
controlling Nginx in another Docker container.

Fixes #1543

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-02-06 22:45:08 +08:00

26 lines
645 B
Go

package docker
import (
"context"
"github.com/docker/docker/client"
)
// Initialize Docker client from environment variables
func initClient() (cli *client.Client, err error) {
cli, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return
}
// Ping the server to ensure the connection is valid and negotiate API version
ping, err := cli.Ping(context.Background())
if err != nil {
return
}
// Explicitly negotiate API version based on the ping response
// This ensures the client uses a compatible API version with the Docker daemon
cli.NegotiateAPIVersionPing(ping)
return
}