Enabling IPv6 Support for Docker and Docker Compose

Learn how to enable IPv6 in Docker and Docker Compose with simple configurations, including testing and custom network setup.

Docker does not enable IPv6 by default, but with a few tweaks, you can configure it to support IPv6 resources, including for Docker Compose. This guide explains how to set up IPv6 for Docker’s default bridge network, ensure Docker Compose also inherits these settings, and configure IPv6 for custom networks.

Prerequisites

  • The latest version of Docker and Docker Compose installed.
  • IPv6 enabled and configured on your host network.

Steps to Enable IPv6

Step 1: Configure Docker Daemon

Edit Docker’s daemon.json file to enable IPv6 and set up a fixed IPv6 subnet:

bash
1
sudo nano /etc/docker/daemon.json

Add the following configuration:

json
1
2
3
4
5
6
7
8
{
  "userland-proxy": false,
  "ipv6": true,
  "ip6tables": true,
  "fixed-cidr-v6": "fd00:1::/64",
  "experimental": true,
  "default-network-opts": {"bridge":{"com.docker.network.enable_ipv6":"true"}}
}

Key Settings Explained:

  • "ipv6": true: Globally enables IPv6 in Docker.
  • "fixed-cidr-v6": "fd00:1::/64": Specifies the IPv6 subnet for Docker containers.
  • "default-network-opts": {"bridge":{"com.docker.network.enable_ipv6":"true"}}: Ensures IPv6 is enabled for the default bridge network and Compose’s default network.

Save and exit the file.

Step 2: Restart Docker

Apply the changes by restarting the Docker service:

bash
1
sudo systemctl restart docker

Step 3: Test IPv6 Connectivity

Run a container and test IPv6 connectivity:

bash
1
sudo docker run --rm -t busybox ping6 -c 4 google.com

If the container can successfully ping an IPv6 resource, the configuration is working.

Step 4: Use Docker Compose with IPv6

Docker Compose automatically uses Docker’s default network, so IPv6 support is now enabled for Compose stacks. Make sure you are using the latest version of Docker Compose.

Example 1: Without Custom Networks

If you do not define a custom network in your docker-compose.yml, Docker Compose will use the default network with IPv6 enabled:

yaml
1
2
3
4
services:
  test:
    image: busybox
    command: ping6 -c 4 google.com

Run the stack:

bash
1
docker-compose up

Your service should now be able to access IPv6 resources.

Example 2: Define IPv6 in a Custom Network (Inside Compose File)

You can also explicitly enable IPv6 for a custom bridge network in your Compose file. Here’s an example:

yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
services:
  app:
    image: busybox
    command: ping6 -c 4 google.com
    networks:
      - app_net

networks:
  app_net:
    driver: bridge
    enable_ipv6: true
    ipam:
      driver: default
      config:
        - subnet: "fd00:2::/64"

Key Points:

  • enable_ipv6: true: Enables IPv6 for the custom network.
  • ipam.config: Defines the IPv6 subnet for the network.

Run the stack:

bash
1
docker-compose up

This approach works without relying on external networks and gives you full control over IPv6 settings.

Step 5: For Non-Compose Setups

If you’re not using Docker Compose, you can create a custom Docker network with IPv6 directly using the docker network create command:

bash
1
2
3
4
docker network create \
    --ipv6 \
    --subnet=fd00:3::/64 \
    my_ipv6_network

You can then run containers with this network:

bash
1
docker run --rm --net my_ipv6_network busybox ping6 -c 4 google.com

Optional: Customize IPv6 Subnet

You can replace the fd00:1::/64 subnet in the daemon.json file or your custom networks with any other IPv6 subnet that suits your network setup. Just ensure it doesn’t conflict with other subnets in your environment.

Conclusion

By following these steps, you’ve enabled IPv6 for Docker’s default network, Docker Compose, and optionally for non-Compose custom networks. Whether you’re using the default configuration or defining custom IPv6 networks in your Compose files, Docker is now ready to handle IPv6 networking for your applications.

Make sure your host network also has IPv6 properly configured to allow seamless access to IPv6 resources.

Happy networking!