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:
|
|
Add the following configuration:
|
|
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:
|
|
Step 3: Test IPv6 Connectivity
Run a container and test IPv6 connectivity:
|
|
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:
|
|
Run the stack:
|
|
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:
|
|
Key Points:
enable_ipv6: true
: Enables IPv6 for the custom network.ipam.config
: Defines the IPv6 subnet for the network.
Run the stack:
|
|
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:
|
|
You can then run containers with this network:
|
|
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!