Skip to content

Commit

Permalink
Added API version negotiation to group.go (#28)
Browse files Browse the repository at this point in the history
* Update lazytainer.go

Negotiate docker API version to prevent "client version is too new" error

* Update group.go

negotiate docker API version
  • Loading branch information
technotiger authored Jul 20, 2023
1 parent 716c1a9 commit 763606e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (lg LazyGroup) MainLoop() {
func (lg LazyGroup) getContainers() []types.Container {
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
check(err)
dockerClient.NegotiateAPIVersion(context.Background())
filter := filters.NewArgs(filters.Arg("label", "lazytainer.group="+lg.groupName))
containers, err := dockerClient.ContainerList(context.Background(), types.ContainerListOptions{All: true, Filters: filter})
check(err)
Expand All @@ -85,6 +86,7 @@ func (lg LazyGroup) stopContainers() {
debugLogger.Println("stopping container(s)")
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
check(err)
dockerClient.NegotiateAPIVersion(context.Background())
for _, c := range lg.getContainers() {
if lg.sleepMethod == "stop" || lg.sleepMethod == "" {
if err := dockerClient.ContainerStop(context.Background(), c.ID, container.StopOptions{}); err != nil {
Expand All @@ -106,6 +108,7 @@ func (lg LazyGroup) startContainers() {
debugLogger.Println("starting container(s)")
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
check(err)
dockerClient.NegotiateAPIVersion(context.Background())
for _, c := range lg.getContainers() {
if lg.sleepMethod == "stop" || lg.sleepMethod == "" {
if err := dockerClient.ContainerStart(context.Background(), c.ID, types.ContainerStartOptions{}); err != nil {
Expand Down

0 comments on commit 763606e

Please sign in to comment.