Closed
Description
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)
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
jpetazzo commentedon Oct 11, 2013
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?Thank you!
marklit commentedon Oct 11, 2013
No I can't connect on
127.0.0.1:8000
. Thelsof
list there is complete and nothing from docker is binded to an IPv4 interface. This was on Ubuntu 13.04 64-bit.jpetazzo commentedon Oct 11, 2013
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 commentedon Oct 11, 2013
I ran all the above on Digital Ocean on their Ubuntu 13.04 x64 image (#350076).
juddmaltin-dell commentedon Oct 27, 2013
[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 commentedon Nov 8, 2013
I was stupidly trying to attach to the port running in the container, not the port on the host OS.
crosbymichael commentedon Dec 13, 2013
@marklit Are you still encountering this issue with a newer version of docker ? We made a lot of fixes to the networking stack.
phsilva commentedon Dec 16, 2013
Still happening on 0.7.1.
gvangool commentedon Dec 23, 2013
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.
If you need extra information, or a test machine. Let me know.
bharrisau commentedon Jan 3, 2014
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 commentedon Jan 7, 2014
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:
the funny thing is that any further process started will work with
docker run -d -p 11211 mc
bharrisau commentedon Jan 7, 2014
From https://groups.google.com/d/msg/golang-nuts/F5HE7Eqb6iM/q_um2VqT5vAJ
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 commentedon Jan 26, 2014
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 commentedon Feb 1, 2014
Having same issue with 0.7.6 are there any workarounds?
187 remaining items