Docker服务更新错误:EOF

huangapple go评论73阅读模式
英文:

Docker Service Update Error: EOF

问题

我们有一个GO应用程序,它监听代码仓库的更改和Redis消息,以便在Docker Swarm环境中应用持续交付(CD)。该应用程序最近更新为使用github.com/docker/docker v1.13.1客户端代码。它在我的运行Docker v1.13.1的Mac上工作正常。但是,当我将此代码部署到运行Ubuntu和Docker v1.12.6的开发服务器上时,尝试调用cli.ServiceUpdate(..)时出现"EOF"错误。据我所知,CLI客户端是向后兼容的(直到v1.10.x或其他版本)。从代码和屏幕截图来看,两者之间的连接是"log message"中的"An error occurred while updating a service"。

尽管我们使用的是v1.13.1版本的golang库,但我们在客户端初始化中指定了api版本v1.24:

func createClient() {
    if cli == nil {
        defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"}
        var err error
        cli, err = client.NewClient("unix:///var/run/docker.sock", "v1.24", nil, defaultHeaders)
        if err != nil {
            panic(err)
        }
    }
}

以下是有问题的代码:

func updateService(s configuration.Service, version string) {
    createClient()

    ctx := context.Background()

    service, _, err := cli.ServiceInspectWithRaw(ctx, configuration.ServiceName(s))
    if err != nil {
        fmt.Println("could not find service", err)
        return
    }

    serviceSpec := createServiceSpec(s, version)

    encodedRegistryAuth := createEncodedRegistryAuth()
    var resp types.ServiceUpdateResponse
    resp, err = cli.ServiceUpdate(ctx, service.ID, service.Version, serviceSpec, types.ServiceUpdateOptions{EncodedRegistryAuth: encodedRegistryAuth})
    if err != nil {
        fmt.Println("An error occurred while updating a service: ", s.Service, "; ", err)
    } else {
        message := "SERVICE UPDATE - " + s.Service + "_" + s.Channel + " >> " + envName + ":" + s.Service + ":" + version
        connections.SlackMessage(message)
        connections.NewRelicDeploy(version, message)
        connections.GrafanaDeploy(version, message)
        fmt.Println("Updated service", s.Service, "and waiting", s.UpdateDelay)
        fmt.Println("Warnings from service update", resp.Warnings)
    }
}

以下是syslog中发生的情况的截图:

Docker服务更新错误:EOF

以下是docker info的输出:

Client:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:40:44 2017
 OS/Arch:      linux/amd64
 Experimental: true

Server:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:40:44 2017
 OS/Arch:      linux/amd64
 Experimental: true

对于我可能做错了什么,你有什么想法吗?

英文:

We have a GO application that listens for code repo changes and Redis messages in order to apply CD in a Docker Swarm environment. That application was recently updated to use the github.com/docker/docker v1.13.1 client code. It worked on my mac, which runs Docker v1.13.1. When I deploy this code to a development server running Ubuntu and Docker v1.12.6, I get an "EOF" error when trying to call cli.ServiceUpdate(..). As far as I know, the CLI client is backwards compatible (until v1.10.x or something). When looking at the code and the screenshot, the connection between the two is the log message of "An error occurred while updating a service".

Event thought we are using the v1.13.1 version of the golang libraries, we specify the api version v1.24 in our client initialization:

func createClient() {
	if cli == nil {
		defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"}
		var err error
		cli, err = client.NewClient("unix:///var/run/docker.sock", "v1.24", nil, defaultHeaders)
		if err != nil {
			panic(err)
		}
	}
}

Here is the offending code:

func updateService(s configuration.Service, version string) {
	createClient()

	ctx := context.Background()

	service, _, err := cli.ServiceInspectWithRaw(ctx, configuration.ServiceName(s))
	if err != nil {
		fmt.Println("could not find service", err)
		return
	}

	serviceSpec := createServiceSpec(s, version)

	encodedRegistryAuth := createEncodedRegistryAuth()
	var resp types.ServiceUpdateResponse
	resp, err = cli.ServiceUpdate(ctx, service.ID, service.Version, serviceSpec, types.ServiceUpdateOptions{EncodedRegistryAuth: encodedRegistryAuth})
	if err != nil {
		fmt.Println("An error occurred while updating a service: ", s.Service, "; ", err)
	} else {
		message := "SERVICE UPDATE - " + s.Service + "_" + s.Channel + " >> " + envName + ":" + s.Service + ":" + version
		connections.SlackMessage(message)
		connections.NewRelicDeploy(version, message)
		connections.GrafanaDeploy(version, message)
		fmt.Println("Updated service", s.Service, "and waiting", s.UpdateDelay)
		fmt.Println("Warnings from service update", resp.Warnings)
	}
}

Here is a screen grab of what happened in syslog:

Docker服务更新错误:EOF

Here is the output from docker info:

Client:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:40:44 2017
 OS/Arch:      linux/amd64
 Experimental: true

Server:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:40:44 2017
 OS/Arch:      linux/amd64
 Experimental: true

Any ideas on what I could be doing wrong?

答案1

得分: 0

事实证明,问题出在某个地方。我们通过停止Docker守护进程,删除/var/lib/docker目录,然后重新启动守护进程来重新构建集群。之后,错误不再出现。

英文:

Turned out to be a fluke somewhere. We rebuilt the swarm by stopping the docker daemon, removing /var/lib/docker, and starting the daemon back up. After that the error no longer occurred.

huangapple
  • 本文由 发表于 2017年2月11日 05:22:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/42168853.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定