Exploring IPv6 with Docker

Today I set out to figure out how to get outbound IPv6 connectivity working with the Docker setup for Mastodon.

Mastodon uses a Docker Compose YAML configuration file to define the various containers it needs to run.

Upon searching for “IPv6 Docker”, you get the following page from the official documentation titled “IPv6 with Docker“. Now this page is actually fine to get a handle on how Docker deals with IPv6 connectivity but it does not actually solve our problem as it does not mention how to configure this in Docker Compose.

The daemon.json file it asks you to modify changes the configuration for the default bridge network that Docker creates. Using a Docker Compose setup creates it’s own separate network for use with that particular application. So, do not worry about modifying that file as it will not be useful for the Mastodon Docker setup.

We do however pick up a couple important tidbits from that page:

  • You need a IPv6 subnet with a size of at least /80. I recommend a routed /64 prefix, my provider of choice, Linode makes this really easy with just a simple ticket to get one assigned to your VM. Well, technically you don’t absolutely *need* a routed prefix, you can have a small on-link prefix and then use NDP proxying but that’s a bit bleh.
  • Docker will add a route, and then modify sysctl values to set IPv6 forwarding to 1.

The Part about Your Mastodon Docker Compose File

Okay, now that I have finished the rather long preamble for this post, let us get to the part y’all came here for. What did I add to the Mastodon Docker Compose YAML file to get outbound IPv6 connectivity?

Well, it’s this (at the very end of the file):

   driver: bridge
   enable_ipv6: true
   driver: default
   - subnet:
   - subnet: 2600:3c02:e000:0058::/64

For this to work, you also need to change the version of the Docker Compose YAML file to 2.1 as that ‘enable_ipv6’ syntax does not work in version 3. Also, replace the IPv6 subnet with your own obviously.

How did I figure this bit out? I used two documentation pages:

After doing that you can bring up the containers with docker-compose up -d and then verify that the containers have IPv6 connectivity with docker network inspect mastodon_default , the output should look like this.

That’s it really. I was expecting to fight Docker a bit more to get this working but I was pleasantly surprised at how easy it was.