12-04-2016 | Remy van Elst | Text only version of this article
At work and at home my ISP's have native IPv6. I recently was at a clients location where they had no IPv6 at all and had to set up and demonstrate an application in a Docker container with IPv6 functionality. They said the had IPv6 but on location it appeared that IPv6 wasn't working. Since IPv6 was required for the demo the container needed a workaround. This article describes the workaround I used to add IPv6 to a Docker container on a non IPv6 network. It was tested on an
Ubuntu 14.04 container, but should work for other Linux distro's as well.
If you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get a $5 VPS for 2 months free (as in, you get $10 credit). Plus, they have a ready to go Docker Ubuntu installation. (referral link)
The workaround involes installing
miredo in the container to get a tunnel and an IPv6 connection that way. Extremely simple, but it required some extra parameters in the Docker workflow.
Miredo is a client for the
teredo protocol. On Ubuntu it is an easy way to add IPv6 to an IPv4 only system. Installing
miredo and starting the service is enough.
First I started the docker container with
docker run, and added an extra parameter, the
--privileged one, like so:
docker run --privileged --name "$APPNAME" "$IMAGENAME"
This gives the container the ability to create a
/dev/net/tun device required for miredo. Otherwise you will get an error like below when starting
/dev/net/tun does not exist.
A Docker container is (to be) used for a single process (as opposed to for example an LXD or OpenVZ container, which are more suited for VPS-like operation) and therefore there is no SSH access or a service manager like
init. Installing software should be done via the Dockerfile in a new container. I needed a way to install and start the
miredo service outside of the Dockerfile for this one instance.
Since this container was to be used only that occasion I used a rather dirty hack to get a shell in the container, install and start the service. It works, but it's not the best way (that would involve setting IPv6 up on the host and configuring the Docker network to also use that in the bridge).
Get the container ID with
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7522a5aedc8b 7.0-apache-openssl-1.1.0 "apache2-foreground" About an hour ago Up About an hour 80/tcp testapp
Open a shell inside of the container, replacing the ID with your container ID:
docker exec -i -t 7522a5aedc8b bash
This gives you a
bash prompt in the container. Install the
apt-get update && apt-get install miredo
Start the service:
service miredo start
Check if the new interface (
miredo) exists and is up:
2: teredo: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1280 qdisc noqueue state UNKNOWN group default qlen 500 link/none inet6 2001:0:53aa:64c:1089:2f63:6e89:5ffc/32 scope global valid_lft forever preferred_lft forever inet6 fe80::ffff:ffff:ffff/64 scope link valid_lft forever preferred_lft forever
You can now close the prompt and continue the container, which has IPv6 connectivity now via this tunnel.
Do note that these changes are temporary. If you stop the container the changes are gone, so on a new run of the container you need to execute these steps again if needed.