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>
This commit is contained in:
Jacky
2026-02-06 22:45:08 +08:00
committed by GitHub
parent ec24adbc35
commit bfc1b21457
+5 -2
View File
@@ -12,11 +12,14 @@ func initClient() (cli *client.Client, err error) {
if err != nil {
return
}
// Optionally ping the server to ensure the connection is valid
_, err = cli.Ping(context.Background())
// 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
}