Make docker use IPv4 for port binding

后端 未结 6 1723
鱼传尺愫
鱼传尺愫 2020-11-29 20:36

I have docker host and inside I have one container.

The docker host is binding the port on IPv6 interface only, not on IPv4.

This is the output



        
相关标签:
6条回答
  • 2020-11-29 21:15

    ISSUE RESOVLED:

    USE docker run -it -p 80:80 --name nginx --net=host -d nginx

    that's issue we face with VM some time instead of bridge network try with host that will work for you

    tcp     0    0 0.0.0.0:80            0.0.0.0:*             LISTEN      - 
    tcp6    0    0 :::80                 :::*                  LISTEN      -  
    
    0 讨论(0)
  • 2020-11-29 21:19

    By default, docker uses AF_INET6 sockets which can be used for both IPv4 and IPv6 connections. This causes netstat to report an IPv6 address for the listening address.

    From RedHat https://access.redhat.com/solutions/3114021

    0 讨论(0)
  • 2020-11-29 21:21

    Setting net.ipv6.conf.all.forwarding=1 will fix the issue.

    This can be done on a live system using sudo sysctl -w net.ipv6.conf.all.forwarding=1

    0 讨论(0)
  • 2020-11-29 21:24

    For CentOS users,

    I've got same issue on CentOS7 and setting net.ipv4.ip_forward to 1 solves the issue. Please, refer to Docker Networking Disabled: WARNING: IPv4 forwarding is disabled. Networking will not work for more details.

    0 讨论(0)
  • 2020-11-29 21:25

    If you want your container ports to bind on your ipv4 address, just :

    • find the settings file
      • /etc/sysconfig/docker-network on RedHat alike
      • /etc/default/docker-network on Debian ans alike
    • edit the network settings
      • add DOCKER_NETWORK_OPTIONS=-ip=xx.xx.xx.xx
      • xx.xx.xx.xx being your real ipv4 (and not 0.0.0.0)
    • restart docker deamon

    works for me on docker 1.9.1

    0 讨论(0)
  • 2020-11-29 21:34

    As @daniel-t points out in the comment: github.com/docker/docker/issues/2174 is about showing binding only to IPv6 in netstat, but that is not an issue. As that github issues states:

    When setting up the proxy, Docker requests the loopback address '127.0.0.1', Linux realises this is an address that exists in IPv6 (as ::0) and opens on both (but it is formally an IPv6 socket). When you run netstat it sees this and tells you it is an IPv6 - but it is still listening on IPv4. If you have played with your settings a little, you may have disabled this trick Linux does - by setting net.ipv6.bindv6only = 1.

    In other words, just because you see it as IPv6 only, it is still able to communicate on IPv4 unless you have IPv6 set to only bind on IPv6 with the net.ipv6.bindv6only setting. To be clear, net.ipv6.bindv6only should be 0 - you can run sysctl net.ipv6.bindv6only to verify.

    0 讨论(0)
提交回复
热议问题