Enable IPv6 in container

Hello! I’m trying to create a Balena single container to run a custom application that I’ve written that uses bind() to create an IPv6 only server listening on a localhost port. The application runs fine on my host machine but every time I try to run the application in the container I’m met with the error “Cannot assign requested address”. Here’s an example snippet:

tcp_fd = socket(AF_INET6, SOCK_STREAM, 0);

memset((void *)&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(port);
addr.sin6_addr = onlylocal ? in6addr_loopback : in6addr_any;
bind(tcp_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0);

On further investigation I found that the container does not have IPv6 at all:

root@f07f785919a8:# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
2: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit brd
23: eth0@if24: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:0a:72:65:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet xxx.xxx.xxx.xxx/24 brd xxx.xxx.xxx.xxx scope global eth0
       valid_lft forever preferred_lft forever

Is there a way to enable IPv6 inside a Balena single container? Additionally, the goal is to connect multiple of these containers using IPV6 sockets, the applications connect and talk to each other using a socket IPC method.

I solved this by creating a file /etc/docker/daemon.json and enabling IPv6, then restarting balena with systemctl restart balena and running a new container.

  "ipv6": true,
  "fixed-cidr-v6": "2001:db8:1::/64"
1 Like

Great to hear you solved this! Thanks for confirming and sharing your fix :slight_smile: