Docker

IPv6 Support in Docker

Internet Protocol or IP address is the backbone of the device networking that is defined in the TCP/IP stack. There are two main common types of Internet Protocol: the first is IPv4 and the second is IPv6.

IPv6, or Internet Protocol version 6, is the network protocol that is designed to succeed IPv5 as the primary protocol for device identity. The central development behind IPv6 is to overcome the limitations of IPv4 which is running out of unique IP addresses due to the growing number of connected devices.

In the context of Docker, IPv6 refers to the support and configuration of IPv6 addressing within the Docker containers. By default, the Docker Engine uses IPv4 addressing which is effective in most scenarios.

However, you might encounter scenarios that require IPv6 connectivity such as in networks transitioning to IPv6 or for applications that specifically rely on IPv6.

In this tutorial, we will learn how to enable the IPv6 support in Docker by configuring the Docker daemon to listen on IPv6-enabled network interface.

Requirements:

To enable the IPv6 networking on Docker, ensure that you have the following tools:

    1. A Linux host (required)
    2. Docker Engine version 20.0 and above
    3. Sufficient permissions to run the commands and alter the system-level features

At the time of writing this tutorial, IPv6 networking is only supported in Linux-based hosts. However, you can reference the documentation to check the support for other hosts.

Enable IPv6 on Docker

The first step to enabling the IPv6 support on Docker is to edit the configuration for your Docker daemon and add the enabled ip6tables which allows for the IPv6 packet filtering rules essential in providing the network isolation and port mapping.

Edit the configuration file with the following command:

$ sudo nano /etc/docker/daemon.json

 
Next, add the configuration entry as follows:

{
  "experimental": true,
  "ip6tables": true
}

 
As you can guess, the previous entry enables the experimental features and sets the ip6tables features to true.

Once done, save the configuration file and restart the Docker daemon for the changes to take effect.

$ sudo systemctl restart docker

 
The next step is to create a new Docker network that uses IPv6. We can do this using the “docker network” command as follows:

$ docker network create --ipv6 –subnet 2001:0DB8::/112 ip6network

 
This should create the network with the previously-specified configuration.

You can also enable IPv6 in a Dockerfile as shown in the following entries:

networks:
   ip6network:
     enable_ipv6: true
     ipam:
       config:
         - subnet: 2001:0DB8::/112

 

Use IPv6 in the Docker Container

Once you created the network, you can create a container that uses the IPv6 network as shown in the following command:

$ docker run --rm --network ip6network -p 80:80 nginx

 
The given command publishes port 80 on both IPv6 and IPv4.

Use IPv6 for the Default Bridge Network

To allow Docker to use IPv6 as the default bridge network, you can configure the Docker daemon and add the entries as follows:

{
  "ipv6": true,
  "fixed-cidr-v6": "2001:db8:1::/64",
  "experimental": true,
  "ip6tables": true
}

 
Save the configuration file and restart the Docker daemon.

Conclusion

This tutorial covered the basics of working and configuring the IPv6 networking support in Docker Engines. Feel free to reference the documentation to learn more.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list