Home Posts Docker IPv6 Support

Docker IPv6 Support

Post Featured Image
Calendar Icon (date post was published) published on  19 Jun 2021
Calendar Icon with Refresh Icon (date post was updated) updated on  26 Jun 2021

By default, IPv6 support is disabled in Docker / Docker containers. This results in any IPv6 only resources (e.g., internet pages, Git repositories, etc.) not being available inside a container.
However, enabling IPv6 support is very easy.

Enable IPv6 Support — Docker Daemon

First, you must determine the IPv6 prefix assigned to your network. If you are behind a private internet connection, you can obtain this information easily from your router administration page.
Now, determine a fixed CIDR subnet/range that your docker daemon may use. For example, if your prefix is 2001:1:1:1::/64, you can simply add 1234 and use an /80 subnet for docker: 2001:1:1:1:1234::/80.

This information has to be added to the /etc/docker/daemon.json file (create it if it does not already exist), along with the setting to enable IPv6 at all:

{
  "ipv6": true,
  "fixed-cidr-v6": "2001:1:1:1:1234::/80"
}

Finally, reload the docker daemon to apply the changes:

systemctl reload docker

Docker will now assign the containers an IPv6 address from within the defined CIDR subnet.

Test IPv6

Simply try to ping/reach an IPv6 resource, e.g. by using curl:

# run following command inside a docker container
curl --ipv6 google.com

# for example, like so (replace google.com by the domain you need access to)
docker run -it --rm curlimages/curl:latest --ipv6 google.com

Automated Update of the Config File

You can use the python script from this Gist to update the config file either manually or via a cronjob or something similar.
Configure the three config variables according to your needs:

  • PREFIX_LENGTH: length of the IPv6 prefix of your internet connection (this information should be shown on your routers admin/configuration interface)
  • TARGET_SUBNET_LENGTH: length of the subnet you want to assign to the docker daemon
  • FILL_WITH: Hexadecimal digits to fill the CIDR range (between network and target-prefix) with

Run the script with at least python version 3:

# put this in a cronjob or run it manually
/usr/bin/python3 dockeripv6update.py

Feel free to use the concepts of the python script to create your own script in any other language or adjust it according to your specific needs!

Categories: