duanne9313 2019-03-09 17:39
浏览 144
已采纳

端口未发布

I have this config (using the go-dockerclient https://github.com/fsouza/go-dockerclient) for a container but it only opens the tcp port when running the container:

...
StartConfig: 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"}},
    },

I tried in every possible way without luck. When I run the container using the cmd it works as expected:

docker run -d \
    -p 0.0.0.0:1053:53/udp \
    -p 0.0.0.0:1053:53/tcp ...

Any ideas what am I doing wrong here?

Container inspect output:

    "NetworkSettings": {
        "Bridge": "",
        "SandboxID": "4bdea4ccda50aaf8a3117098fdd2073943af43e8d991ddd7a0be425c5599dfbd",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Ports": {
            "53/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "1053"
                }
            ]
        },
        "SandboxKey": "/var/run/docker/netns/4bdea4ccda50",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null,
        "EndpointID": "1796f8bda73d13d354bcd8bafaf6c1f4ff1491582c3985f6b653ccc6b2226e01",
        "Gateway": "172.17.0.1",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "IPAddress": "172.17.0.3",
        "IPPrefixLen": 16,
        "IPv6Gateway": "",
        "MacAddress": "02:42:ac:11:00:03",
        "Networks": {
            "bridge": {
                "IPAMConfig": null,
                "Links": null,
                "Aliases": null,
                "NetworkID": "fb85e54ede4e18ae48e4c889d169d2d4cd8b2087a8c9691e094a431cb6a7eb43",
                "EndpointID": "1796f8bda73d13d354bcd8bafaf6c1f4ff1491582c3985f6b653ccc6b2226e01",
                "Gateway": "172.17.0.1",
                "IPAddress": "172.17.0.3",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:42:ac:11:00:03"
            }
        }
    }
  • 写回答

1条回答 默认 最新

  • douzi4724 2019-03-09 18:29
    关注

    I have tried the following example which worked as expected for me, the example as shown below:

    The docker image link: https://github.com/sameersbn/docker-bind

    Maybe the issue is related with the image that you have?

    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 inspect results:

    "Ports": {
      "10000/tcp": null,
      "53/tcp": [
        {
          "HostIp": "0.0.0.0",
          "HostPort": "1053"
        }
      ],
      "53/udp": [
        {
          "HostIp": "0.0.0.0",
          "HostPort": "1053"
        }
      ]
    },
    
    

    Make sure that you have this in your Dockerfile as by default EXPOSE assumes TCP as described in here:

    EXPOSE 53/udp 53/tcp
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。