fix: handle docker client api version < 1.44

This commit is contained in:
nemezo 2024-11-06 14:39:30 +01:00
parent c6b15bb5b2
commit efabfca8b2
No known key found for this signature in database

View file

@ -7,7 +7,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
@ -243,6 +242,7 @@ func (client dockerClient) GetNetworkConfig(c t.Container) *network.NetworkingCo
ep.Aliases = aliases ep.Aliases = aliases
} }
return config return config
} }
@ -264,6 +264,17 @@ func (client dockerClient) StartContainer(c t.Container) (t.ContainerID, error)
return &network.NetworkingConfig{EndpointsConfig: oneEndpoint} return &network.NetworkingConfig{EndpointsConfig: oneEndpoint}
}() }()
// Docker Client API Version 1.43 and below Conflict setting MAC address
// See: https://github.com/moby/moby/blob/f0cec02a403496e2b1dd1aaf12b2530922e210db/client/container_create.go#L40
if client.api.ClientVersion() < "1.44" {
for _, endpoint := range networkConfig.EndpointsConfig {
endpoint.MacAddress = ""
}
log.Infof("Detected Docker API version %s, which is incompatible with setting MAC address for endpoints.",
client.api.ClientVersion())
log.Infof("Skipping MAC address configuration to maintain api compatibility.")
}
name := c.Name() name := c.Name()
log.Infof("Creating %s", name) log.Infof("Creating %s", name)
@ -445,7 +456,7 @@ func (client dockerClient) ExecuteCommand(containerID t.ContainerID, command str
clog := log.WithField("containerID", containerID) clog := log.WithField("containerID", containerID)
// Create the exec // Create the exec
execConfig := types.ExecConfig{ execConfig := container.ExecOptions{
Tty: true, Tty: true,
Detach: false, Detach: false,
Cmd: []string{"sh", "-c", command}, Cmd: []string{"sh", "-c", command},
@ -456,7 +467,7 @@ func (client dockerClient) ExecuteCommand(containerID t.ContainerID, command str
return false, err return false, err
} }
response, attachErr := client.api.ContainerExecAttach(bg, exec.ID, types.ExecStartCheck{ response, attachErr := client.api.ContainerExecAttach(bg, exec.ID, container.ExecStartOptions{
Tty: true, Tty: true,
Detach: false, Detach: false,
}) })
@ -465,7 +476,7 @@ func (client dockerClient) ExecuteCommand(containerID t.ContainerID, command str
} }
// Run the exec // Run the exec
execStartCheck := types.ExecStartCheck{Detach: false, Tty: true} execStartCheck := container.ExecStartOptions{Detach: false, Tty: true}
err = client.api.ContainerExecStart(bg, exec.ID, execStartCheck) err = client.api.ContainerExecStart(bg, exec.ID, execStartCheck)
if err != nil { if err != nil {
return false, err return false, err