This is a text-only version of the following page on https://raymii.org: --- Title : IPv6 in a Docker container on a non-ipv6 network Author : Remy van Elst Date : 12-04-2016 URL : https://raymii.org/s/articles/IPv6_in_a_Docker_container_on_a_non-ipv6_network.html Format : Markdown/HTML --- 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 $100 credit for 60 days.

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][2] 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: 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. [1]: https://www.digitalocean.com/?refcode=7435ae6b8212 [2]: https://en.wikipedia.org/wiki/Miredo --- License: All the text on this website is free as in freedom unless stated otherwise. This means you can use it in any way you want, you can copy it, change it the way you like and republish it, as long as you release the (modified) content under the same license to give others the same freedoms you've got and place my name and a link to this site with the article as source. This site uses Google Analytics for statistics and Google Adwords for advertisements. You are tracked and Google knows everything about you. Use an adblocker like ublock-origin if you don't want it. All the code on this website is licensed under the GNU GPL v3 license unless already licensed under a license which does not allows this form of licensing or if another license is stated on that page / in that software: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Just to be clear, the information on this website is for meant for educational purposes and you use it at your own risk. I do not take responsibility if you screw something up. Use common sense, do not 'rm -rf /' as root for example. If you have any questions then do not hesitate to contact me. See https://raymii.org/s/static/About.html for details.