运行Docker 18.09.1,API 1.39,并尝试将容器的网络置于主机模式,这样蓝牙才能正常工作。当我从CLI启动容器时,一切都很完美:
docker run --rm --name mycontainer --net=host imageName my-command当我试图使用Go API启动这个容器时,网络似乎没有被正确设置,导致我的容器死亡。
config := &container.Config{
Cmd: []string{"my-command"},
Hostname: "mycontainer",
Image: imageName,
}
hostConfig := &container.HostConfig{
AutoRemove: true,
NetworkMode: "host",
}
container, err := cli.ContainerCreate(*ctx, config, hostConfig, nil, "mycontainer")很明显,我错过了一些东西,但我看不出那是什么。我是否需要一个网络配置( nil参数到ContainerCreate),因为我指定了网络模式?
发布于 2019-02-15 00:05:53
当我准备发布这个问题时,我发现了我的问题,所以我将分享它,因为这在任何文档中都不是明确的。当使用host网络模式时,容器配置不应该有主机名。
改变这种情况:
config := &container.Config{
Cmd: []string{"my-command"},
Hostname: "mycontainer",
Image: imageName,
}...to这个:
config := &container.Config{
Cmd: []string{"my-command"},
Image: imageName,
}就这么做了。
https://stackoverflow.com/questions/54700942
复制相似问题