Skip to content

Port redirecting binding to IPv6 but not IPv4 interfaces. #2174

Closed
@marklit

Description

@marklit

Is there a way I can tell docker to only bind redirected ports to IPv4 interfaces?

I have a machine running with IPv6 disabled:

# echo '1' > /proc/sys/net/ipv6/conf/lo/disable_ipv6  
# echo '1' > /proc/sys/net/ipv6/conf/lo/disable_ipv6  
# echo '1' > /proc/sys/net/ipv6/conf/all/disable_ipv6  
# echo '1' > /proc/sys/net/ipv6/conf/default/disable_ipv6
# /etc/init.d/networking restart

ifconfig reports there are no IPv6-enabled interfaces:

# ifconfig
docker0   Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:1372 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7221 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:88091 (88.0 KB)  TX bytes:10655750 (10.6 MB)

eth0      Link encap:Ethernet  HWaddr 04:01:08:c1:b1:01  
          inet addr:198.XXX.XXX.XXX  Bcast:198.199.90.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:97602 errors:0 dropped:4 overruns:0 frame:0
          TX packets:15362 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:141867997 (141.8 MB)  TX bytes:1376970 (1.3 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lxcbr0    Link encap:Ethernet  HWaddr 9e:51:04:ed:13:d4  
          inet addr:10.0.3.1  Bcast:10.0.3.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

When I launch a new docker container and ask it to port forward 8000 to 8000 in the container it does so only on IPv6 interfaces. Is there a way to make it only bind to IPv4 interfaces?

# docker run -p 8000:8000 -i -t colinsurprenant/ubuntu-raring-amd64 /bin/bash

When I check with lsof it says that only IPv6-related bindings have been made:

# lsof -OnP | grep LISTEN
sshd      1275             root    3u     IPv4 ... TCP *:22 (LISTEN)
sshd      1275             root    4u     IPv6 ... TCP *:22 (LISTEN)
dnsmasq   2975      lxc-dnsmasq    7u     IPv4 ... TCP 10.0.3.1:53 (LISTEN)
docker    9629             root    7u     IPv6 ... TCP *:8000 (LISTEN)
docker    9629 9630        root    7u     IPv6 ... TCP *:8000 (LISTEN)
docker    9629 9631        root    7u     IPv6 ... TCP *:8000 (LISTEN)
docker    9629 9632        root    7u     IPv6 ... TCP *:8000 (LISTEN)
docker    9629 9633        root    7u     IPv6 ... TCP *:8000 (LISTEN)
docker    9629 9634        root    7u     IPv6 ... TCP *:8000 (LISTEN)
docker    9629 9698        root    7u     IPv6 ... TCP *:8000 (LISTEN)

Activity

jpetazzo

jpetazzo commented on Oct 11, 2013

@jpetazzo
Contributor

I believe that while IPv6 is disabled on all interfaces, it is not disabled on the whole machine. In other words, even if there is no IPv6 interface or address present at the moment, there might be one in the future. So when Docker tells to the kernel "please bind my sockets to all available addresses", it will include IPv6.

When you try to connect to your IPv4 address (e.g. 127.0.0.1:8000) does it work or not?

  • If it doesn't work, it is indeed a serious bug!
  • If it works, then can you explain why the behavior is a problem, so we can find the best fix?

Thank you!

marklit

marklit commented on Oct 11, 2013

@marklit
Author

No I can't connect on 127.0.0.1:8000. The lsof list there is complete and nothing from docker is binded to an IPv4 interface. This was on Ubuntu 13.04 64-bit.

jpetazzo

jpetazzo commented on Oct 11, 2013

@jpetazzo
Contributor

OK! I was asking because on my machine, many sockets show as IPv6 even though IPv4 works fine. Thanks for the precision. We'll try to reproduce here.

marklit

marklit commented on Oct 11, 2013

@marklit
Author

I ran all the above on Digital Ocean on their Ubuntu 13.04 x64 image (#350076).

juddmaltin-dell

juddmaltin-dell commented on Oct 27, 2013

@juddmaltin-dell

[SOLVED] pebcak, picnic.

I'm hitting this too. (frowny)

uname -a

Linux d08-00-27-49-4f-76 3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 16:19:23 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

docker -v

Docker version 0.6.4, build 2f74b1c

cat /etc/issue

Ubuntu 12.04.3 LTS \n \l

newgoliath

newgoliath commented on Nov 8, 2013

@newgoliath

I was stupidly trying to attach to the port running in the container, not the port on the host OS.

crosbymichael

crosbymichael commented on Dec 13, 2013

@crosbymichael
Contributor

@marklit Are you still encountering this issue with a newer version of docker ? We made a lot of fixes to the networking stack.

phsilva

phsilva commented on Dec 16, 2013

@phsilva

Still happening on 0.7.1.

gvangool

gvangool commented on Dec 23, 2013

@gvangool

I have installed it on clean Centos 6.5. And Docker works out-of-the box (epel installs Docker version 0.7.0, build 0ff9bc1/0.7.0).

But my containers only bind on the IPv6 side, not on IPv4.

# netstat -ntple
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       User       Inode      PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      0          7904       898/sshd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      0          8151       926/sendmail
tcp        0      0 :::80                       :::*                        LISTEN      0          8760       966/docker
tcp        0      0 :::22                       :::*                        LISTEN      0          7906       898/sshd
tcp        0      0 :::443                      :::*                        LISTEN      0          8755       966/docker
# docker ps
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS              PORTS                                      NAMES
51bd237afd47        proxy:latest              nginx               14 minutes ago      Up 12 minutes       0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp   lb0
#  uname -a                                                                                                                                                                  
Linux docker0 2.6.32-431.1.2.0.1.el6.x86_64 #1 SMP Fri Dec 13 13:06:13 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

If you need extra information, or a test machine. Let me know.

bharrisau

bharrisau commented on Jan 3, 2014

@bharrisau

Using Docker version 0.7.1, build 8088bc1/0.7.1. I get the same, except it all works with IPv4.

e.g. If I were to do 'telnet -4 localhost 80' in the example above it would connect through. It doesn't work for external connections, but I think that is a different issue.

aheissenberger

aheissenberger commented on Jan 7, 2014

@aheissenberger

I have the same problem with Version 0.7.3 that after starting boot2docker only adding 0.0.0.0 works:
docker run -d -p 0.0.0.0::11211 mc

this does not work:
docker run -d -p 11211 mc

in both cases the result from docker ps is `0.0.0.0:49154->11211/tcp'
and netstat shows that there was only an IP6 Binding:

sudo netstat -ntple
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      520/sshd
tcp        0      0 :::49153                :::*                    LISTEN      684/docker
tcp        0      0 :::4243                 :::*                    LISTEN      684/docker
tcp        0      0 :::22                   :::*                    LISTEN      520/sshd

the funny thing is that any further process started will work with docker run -d -p 11211 mc

bharrisau

bharrisau commented on Jan 7, 2014

@bharrisau

From https://groups.google.com/d/msg/golang-nuts/F5HE7Eqb6iM/q_um2VqT5vAJ

on linux, by default, net.ipv6.bindv6only is 0, so ipv4 packets could also be received from
ipv6 sockets with ipv4-mapped ipv6 address. thus you only need to listen on tcp6 socket
and we can support both ipv4 and ipv6.

if you want explicitly only listen on ipv4 port, you will have to use net.Listen("tcp4", "0.0.0.0:3000")
and then pass the listener to http.Serve.

This is why binding to the IPv6 loopback also binds to the IPv4 loopback (though netstat won't show it). Most of the work is done by the iptables -t nat stuff anyway.

matschaffer

matschaffer commented on Jan 26, 2014

@matschaffer

FWIW, I found this issue trying to figure out why a port mapping wouldn't work from my host OS (host -> vagrant -> docker container). I tried another box and it worked even though I only had the tcp6 port listed in netstat. Thinking something else may be happening here but not sure what.

UPDATE: yeah, just destroyed and recreated the VM and now it's fine. Yay computers ;)

shulcsm

shulcsm commented on Feb 1, 2014

@shulcsm

Having same issue with 0.7.6 are there any workarounds?

187 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/networkingexp/expertkind/bugBugs are bugs. The cause may or may not be known at triage time so debugging may be needed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @matschaffer@farcaller@phsilva@gvangool@teepark

        Issue actions

          Port redirecting binding to IPv6 but not IPv4 interfaces. · Issue #2174 · moby/moby