Bobcares

Alpine Docker enable IPv6 : How to?

by | Aug 17, 2022

In this article, we will see how to enable alpine Docker IPv6 support with simple steps with our Docker hosting support Service, we can give you an absolute step-by-step guide on the entire process.

How to enable alpine Docker IPv6 support

Docker is a platform as a service (PaaS) product based that use the Operating system level to deliver software in different packages called containers.  Alpine is a security-oriented-based lightweight Linux distribution utility platform.  We will now move on to enabling alpine Docker with simple steps:

First, create a JSON file “/etc/docker/daemon.json ” and write a key of ipv6 value to true and a key fixed-cidr-v6 IPv6 prefix added. This prefix will be allocated to the default docker bridge network docker 0.

{ "ipv6": true, "fixed-cidr-v6": "2001:db8:abc1::/64" }

Save the File and restart the docker:

systemctl restart docker

Execute the commanddocker network ls. This lists all the networks that the engine knows about. You will get the following result:

$ docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
9ac6696dded9   bridge    bridge    local
bcc12f998444   host      host      local
32126ee8d073   none      null      local

Now inspect the default docker ‘bridge’ network with the command:

docker network inspect bridge.

You will get IPv6 network and gateway address listed by now.

$ docker network inspect bridge

Execute the ” ip add ” command to output the docker 0 interface IPv6 address

Create an IPv6 container

You can create a container using docker create ordocker run. However, by default this is assigned to the docker0 bridge network and has an IPv4 & IPv6 address:

$ docker run -di --name alpine6-1 alpine
0f1e634aacf45bfccca1494d6804bbaeac21b870152ceebdaeea8ad72ae27b3d
$ docker exec alpine6-1 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
   valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
   valid_lft forever preferred_lft forever
22: eth0@if23: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
   valid_lft forever preferred_lft forever
inet6 2001:db8:abc1::242:ac11:2/64 scope global flags 02
   valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:2/64 scope link
   valid_lft forever preferred_lft forever

Now we need to  check the connectivity by pining  the local gateway:

docker exec alpine6-1 ping6 2001:db8:abc1::1 

The docker 0 network has the default bridge network. By default, containers assigned to it will have IPv4 and IPv6 connectivity to the local gateway and each other.

However, due to limitations with the docker0 network, it is advised that the docker network should not be used in Production environments, user-defined bridge networks should be used instead.

User-defined bridge network build

  • The user-defined bridge network is similar to the docker0 network it will occupy on the docker host, and this host acts as the network’s gateway.
  • The containers assigned to a user-defined bridge network will have access to other containers and to the gateway to the same or to external networks.
  •  The role of a gateway is performed by Docker. However, the external networks will need to have the necessary routing data to be able to communicate with the custom network.

Build Step-by-step Procedure

  • Initially enable IPv6 for docker.
  • Next, create a new IPv6 bridge network :
    docker network create --subnet="<your-v6-prefix>" \ --gateway="your-gateway-address" \ --ipv6 \ <name-of-bridge-network>
  • Attach a container to this network using the --network flag for docker run.
  • Verify with docker network inspect <your-network>.
  • Ensure destination networks have a route to <your-v6-prefix>for external access

In this example, we have used the IPv6 prefix. Containers on this network communicate with external destinations, the external nodes will need the routing information to the internal v6 network.

External communication for IPv6 containers

  • In this sample, we have used the IPv6 prefix. Containers on this network communicate with external destinations, the external nodes will need the routing information to the internal v6 network.
  • If you want containers with public internet access then their attached network will require to be a globally routable prefix.
  • In this case, we chose IPvlan Layer 2 docker network, this uses the docker host’s IPv6 network. Therefore the network is ISP globally assigned routable network.

IPvlan network build

In this scenario, we will try to Perform using the default L2 mode. Because in this mode, the docker host parent interface will operate at Layer 2 only and it switches the traffic from containers to the external gateway. Here the ISP router will forward the traffic to the public internet.

alpine docker enable ipv6

Process Method

First, create the IPvlan network using the following command:

docker network create -d ipvlan \
--subnet=<your-network-address>::/64 \ 
--gateway=<your-gateway-address> \
--ipv6 -o parent=<your-host-parent-interface> \ 
<your-network-name>

Check ‘the IP address to confirm the interface name. The created network is meant to be a dual-stack, with both IPv4 and IPv6 addressing. Unless you configure the IPv4, it is a /16 taken from the 172/8 range.

Further, create a new container and connect it to the IPvlan network.

docker run -di --name alpine6-2 \
  --network <your-network-name> alpine

A container will be created and this attaches to the IPvlan network. This implies the container is dual-stack with an IPv4 address and IPv6 address. Later, verify with ip addr.

In the final analysis ping an IPv6 site for testing, such as youtube.com or google.

[Need assistance with similar queries? We are here to help]

Conclusion

You can now create the new networks with the –ipv6 and can also assign containers IPv6 addresses using the –ip6 flag. Docker supports IPv6 addressing and IPv6 network and has a better user-defined bridge network. All things considered, IPvlan network with access to the public Internet.

PREVENT YOUR SERVER FROM CRASHING!

Never again
lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server
24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.