Raymii.org
Quis custodiet ipsos custodes?Home | About | All pages | Cluster Status | RSS Feed
IPv6 in a Docker container on a non-ipv6 network
Published: 12-04-2016 | Author: Remy van Elst | Text only version of this article
❗ This post is over seven years old. It may no longer be up to date. Opinions may have changed.
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.
Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:
I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!
Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.
You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $200 credit for 60 days. Spend $25 after your credit expires and I'll get $25!
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 miredo
:
/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
systemd
or 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 docker ps
:
docker ps
Output:
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 miredo
package:
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.
Tags: articles , containers , docker , ipv6 , lxc , miredo , teredo