1 回答
TA贡献1779条经验 获得超6个赞
我已经尝试了以下示例,它对我来说按预期工作,示例如下所示:
docker镜像链接: https: //github.com/sameersbn/docker-bind
也许问题与您拥有的图像有关?
package main
import (
docker "github.com/fsouza/go-dockerclient"
)
func main() {
endpoint := "unix:///var/run/docker.sock"
client, err := docker.NewClient(endpoint)
if err != nil {
panic(err)
}
container, err := client.CreateContainer(docker.CreateContainerOptions{
Name: "my-container",
Config: &docker.Config{Image: "sameersbn/bind:9.11.3-20190113"},
HostConfig: &docker.HostConfig{
PortBindings: map[docker.Port][]docker.PortBinding{
"53/tcp": {{HostIP: "0.0.0.0", HostPort: "1053"}},
"53/udp": {{HostIP: "0.0.0.0", HostPort: "1053"}},
},
},
},
)
client.StartContainer(container.ID, nil)
}
Docker 检查结果:
"Ports": {
"10000/tcp": null,
"53/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "1053"
}
],
"53/udp": [
{
"HostIp": "0.0.0.0",
"HostPort": "1053"
}
]
},
确保您的 Dockerfile 中包含此内容。
- 1 回答
- 0 关注
- 137 浏览
添加回答
举报