Enabling IPv6 Support and IPv6 Listening in Docker
By default, Docker does not support IPv6 listening and access after installation. If your server supports IPv6 and you have IPv6 requirements, you can enable IPv6 support using the methods below.

My Scenario
Let me first describe my scenario. Recently, I had a special requirement where a specific port of a container needed to be accessible only via IPv6, without supporting IPv4 access. However, the default situation is the opposite: it supports IPv4 access but not IPv6 access. Therefore, I needed to enable IPv6 support in Docker and configure IPv6 listening.
Enable IPv6 in Docker
Modify the Docker configuration file /etc/docker/daemon.json. If it does not exist, create it. Then copy the following content and save it:
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}
2001:db8:1::/64is a virtual IPv6 subnet; you can keep the default value as shown above.
Then run the command systemctl reload docker to reload the Docker service. This enables Docker to support IPv6 listening and access.
Listen Only on IPv6 Addresses
To achieve the goal of blocking IPv4 access and supporting only IPv6 access, further configuration is required. By default, we can specify the listening IP and mapped port using the -p parameter. For example, to listen on 127.0.0.1:80, you can do the following:
docker run -itd --name="onenav" -p 127.0.0.1:80:80 \
-v /data/onenav:/data/wwwroot/default/data \
helloz/onenav:0.9.27
If you only need to support IPv6 listening and access, you must use [] to specify the IPv6 IP address after the -p parameter when starting the container:
docker run -itd --name="onenav" -p [2a12:a301:2::1126]:80:80 \
-v /data/onenav:/data/wwwroot/default/data \
helloz/onenav:0.9.27
- If specifying an IPv6 address for listening, it must be enclosed in
[]. - Replace
2a12:a301:2::1126with your own public IPv6 address.
If you need to support both IPv4 and IPv6 listening and access simultaneously, simply remove the IP address after the -p parameter and keep only the port:
docker run -itd --name="onenav" -p 80:80 \
-v /data/onenav:/data/wwwroot/default/data \
helloz/onenav:0.9.27
Summary
- Docker does not enable IPv6 support by default; it must be enabled by modifying the configuration file.
- After enabling IPv6 support in Docker, it will listen on both IPv4 and IPv6 by default.
- If you only need IPv6 address access, you must specify the
[ipv6_address]after the-pparameter, and the IPv6 address must be enclosed in[].
Some content in this article is referenced from: https://docs.docker.com/config/daemon/ipv6/