Enabling IPV6 Support and IPV6 Listening in Docker

Publish: 2022-11-21 | Modify: 2022-11-21

After Docker is installed, it does not support IPV6 listening and access by default. If your server supports IPV6 and you have IPV6 requirements, you can enable IPV6 support by following the steps below.

IPv6

My Scenario

First, let me talk about my scenario. I have a special requirement recently, which requires that a specific port of the container can only be accessed through IPV6 and does not support IPV4 access. However, the default situation is the opposite. Currently, it supports IPV4 access but not IPV6 access. Therefore, Docker needs to be enabled with IPV6 support and set up IPV6 listening.

Enable IPV6 in Docker

Modify the Docker configuration file /etc/docker/daemon.json, if it does not exist, create one. Then copy the following content and save it:

{
  "ipv6": true,
  "fixed-cidr-v6": "2001:db8:1::/64"
}
  • 2001:db8:1::/64 is a virtual IPV6 network segment, keep the above default and copy it down.

Then enter the command: systemctl reload docker to reload the Docker service once, so that Docker supports IPV6 listening and access.

Only Listen to IPV6 Addresses

If you want to implement blocking IPV4 access and only support IPV6 access, further operations are required. By default, we can specify the listening IP and mapped port through the -p parameter. For example, we can specify to listen to 127.0.0.1:80 like this:

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, then when starting the container, we need to specify the IPV6 IP listening after the -p parameter with [], for example:

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 the IPV6 address to listen, it needs to be enclosed in [].
  • Change 2a12:a301:2::1126 to your own public IPV6 address.

If you need to support both IPV4 and IPV6 listening and access, just remove the IP address after the -p parameter and keep only the port, for example:

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 and needs to be enabled by modifying the configuration file.
  • After Docker enables IPV6 support, it will listen to both IPV4 and IPV6 by default.
  • If you only need IPV6 address access, you need to specify it with [ipv6 address] after the -p parameter, and the IPV6 address needs to be enclosed in [].

Some of the content in this article is referenced from: https://docs.docker.com/config/daemon/ipv6/


Comments