Enable IPv6 with Docker

self-hosted May 9, 2022

With the ever-increasing need for internet-connected devices, IPv6 addresses provide a solution for the shortage of IPv4 addresses. As a result, it's important to have the ability to also run containers with IPv6 addresses within a docker network.

This short article will guide you through the process of setting up and using an IPv6 network in Docker. By the end of this tutorial, you'll be able to use IPv6 addresses with your Docker containers and networks, which will be particularly useful if you're using Nginx Proxy or similar applications. You just need basic knowledge with IP addressing

I wrote this as a personal reference, a memo for myself.

Let's get started! It is super easy you'll see !

Enable IPv6 Support in Docker Daemon

To use IPv6 in Docker containers or swarm services, you need to enable IPv6 support in the Docker daemon. To do this, follow these steps:

  1. Open the Docker daemon configuration file by running the following command in the terminal: nano /etc/docker/daemon.json
  2. Modify the file to include the following content:
{
  "ipv6": true,
  "fixed-cidr-v6": "fdd1:b19:abc1::1/48",
  "ip6tables": true
}

Note: IPv6 networking is only supported on Docker daemons running on Linux hosts.

You will need to restart the docker daemon to enable our changes by running the following command in the terminal: systemctl restart docker .

Then to make sure our changes are effective inspect the bridge network by running the following command in the terminal: docker network inspect bridge.

This will display information about the bridge network. You should see the IPv6 subnet we created. Verify that the subnet match the values specified in the previous step.

If you create a new container by default it will be assigned to the docker0 bridge network and have an IPv4 & IPv6 address/connectivity to the local gateway and each other. However, docker advises against using the docker0 network in production environments and recommends using user-defined bridge networks instead.

Let's see how !

Creating an user-defined bridge network

To create a new IPv6 bridge network with specific properties, use the following command in the terminal:

docker network create --subnet="fdd1:b20:abc1::/48" \
--gateway="fdd1:b20:abc1::1" \
--ipv6 \
mynetwork

This command creates a new user-defined network named mynetwork with the specified subnet fdd1:b20:abc1::/48 and gateway fdd1:b20:abc1::1 .
The --ipv6 flag is used to specify that the network should be created with IPv6 addresses.

Note that the network driver is set to bridge by default.

Create a container and connect it to the IPv6 Network

To create a new container and connect it to the IPv6 network you just need to attach it to our newly created network.

docker run -di -p 8000:80 --name nginx \
    --network mynetwork \
    nginx:latest

This command creates a new nginx container, and connects it to our IPv6 network with the flag --network mynetwork .

In this tutorial, we covered how to enable IPv6 support in the Docker daemon, create a new IPv6 bridge network, and create a Docker container connected to the network. By following these steps, you should now have a working IPv6 network in Docker that you can use for your projects.

If you have any questions, feel free to contact me. Happy Docker-ing!

Official documentation: https://docs.docker.com/config/daemon/ipv6/

Tags

Faceslog

CS Student. I love reverse engineering and IT stuff.