# ZeroTier One in a container! **NOTE:** _Most of this information pertains to the docker image only. For more information about ZeroTier, check out the repository_: [here](https://github.com/zerotier/ZeroTierOne) or the [commercial website](https://www.zerotier.com). [ZeroTier](https://www.zerotier.com) is a smart programmable Ethernet switch for planet Earth. It allows all networked devices, VMs, containers, and applications to communicate as if they all reside in the same physical data center or cloud region. This is accomplished by combining a cryptographically addressed and secure peer to peer network (termed VL1) with an Ethernet emulation layer somewhat similar to VXLAN (termed VL2). Our VL2 Ethernet virtualization layer includes advanced enterprise SDN features like fine grained access control rules for network micro-segmentation and security monitoring. All ZeroTier traffic is encrypted end-to-end using secret keys that only you control. Most traffic flows peer to peer, though we offer free (but slow) relaying for users who cannot establish peer to peer connections. The goals and design principles of ZeroTier are inspired by among other things the original [Google BeyondCorp](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43231.pdf) paper and the [Jericho Forum](https://en.wikipedia.org/wiki/Jericho_Forum) with its notion of "deperimeterization." Visit [ZeroTier's site](https://www.zerotier.com/) for more information and [pre-built binary packages](https://www.zerotier.com/download/). Apps for Android and iOS are available for free in the Google Play and Apple app stores. ZeroTier is licensed under the [BSL version 1.1](https://mariadb.com/bsl11/). See [LICENSE.txt](https://github.com/zerotier/ZeroTierOne/blob/master/LICENSE.txt) and the [ZeroTier pricing page](https://www.zerotier.com/pricing) for details. ZeroTier is free to use internally in businesses and academic institutions and for non-commercial purposes. Certain types of commercial use such as building closed-source apps and devices based on ZeroTier or offering ZeroTier network controllers and network management as a SaaS service require a commercial license. A small amount of third party code is also included in ZeroTier and is not subject to our BSL license. See [AUTHORS.md](https://github.com/zerotier/ZeroTierOne/blob/master/AUTHORS.md) for a list of third party code, where it is included, and the licenses that apply to it. All of the third party code in ZeroTier is liberally licensed (MIT, BSD, Apache, public domain, etc.). ## Building the docker image Due to the network being a substrate for most applications and not an application unto itself, it makes sense that many people would want to build their own image based on our formula. The image is based on `debian:buster`. The `Dockerfile.release` file contains build instructions for building the described image in the rest of the README. The build is multi-arch and multi-release capable. These build arguments power the build: - `PACKAGE_BASEURL`: The base URL of the package repository to fetch from. (default: `https://download.zerotier.com/debian/buster/pool/main/z/zerotier-one/`) - `ARCH`: The architecture of the package, in debian format. Must match your image arch. (default: `amd64`) - `VERSION`: **REQUIRED** the version of ZeroTier to fetch. You can build this image like so: ``` docker build -f Dockerfile.release -t mybuild --build-arg VERSION=1.6.5 . ``` ## The controller image (`Dockerfile.controller`) `Dockerfile.controller` builds BackOne with the embedded network controller enabled and its default `FileDB` backend, with PostgreSQL, Redis and the Rust `smeeclient` library left out of the build entirely. That is what `ZT_CONTROLLER_NO_SQL=1` buys you: no `libpq-dev`, no cargo toolchain, and no `ext/*/install/ubuntu22.04/$(EXT_ARCH)` prebuilts, so the image builds on any Debian base instead of being pinned to the host distribution the vendored prebuilts were cut for. ``` sudo docker build -f Dockerfile.controller -t backone-controller . sudo docker run -d --name backone-ctl \ --cap-add NET_ADMIN --device /dev/net/tun \ -v backone-ctl:/var/lib/backone \ --network host \ backone-controller /usr/sbin/backone -U -p9993 ``` The controller is on by default; there is nothing to configure. Keep `/var/lib/backone` on a volume — it holds `identity.secret` and `controller.d/`, and replacing the container without it changes the node address and loses network state. `--network host`, not `-p 9993:9993`. The API authorizes loopback source addresses only, unless `settings.allowManagementFrom` widens it (`service/OneService.cpp:1859`), and a published port arrives at the container after DNAT — from the bridge gateway, not loopback — so it answers `401` no matter how correct the token is. Drive the API from inside the container: ``` sudo docker exec backone-ctl sh -c \ 'curl -sS -H "X-ZT1-Auth: $(cat /var/lib/backone/authtoken.secret)" http://127.0.0.1:9993/controller/network' ``` To reach the API from another host, bind it to the container's own port with `allowManagementFrom` set to the network you intend to allow, and then treat the token as a credential exposed to that network. To verify an image rather than trust that it built, run the gate. It asserts the binary carries no PostgreSQL/Redis/smeeclient symbols and then drives a live network create → member authorize → member list → on-disk check through the controller, because a build with an unconfigured SQL backend compiles cleanly and fails only at runtime: ``` tools/controller-image-gate.sh # build the image, then gate it tools/controller-image-gate.sh --local # gate ./backone without docker tools/controller-image-gate.sh --image NAME --port N # gate an image already built ``` `make central-controller` and `ZT_CONTROLLER=1` on its own are unchanged: they still build with PostgreSQL and Redis available. `ZT_CONTROLLER_NO_SQL=1` is an opt-out from that, never a redefinition of it. ## Using the docker image The `entrypoint.sh` in the docker image is a little different; zerotier will be spawned in the background and the "main process" is actually just a sleeping shell script. This allows `zerotier-one` to gracefully terminate in some situations largely unique to docker. The `zerotier/zerotier` image requires the `CAP_NET_ADMIN` capability and the `/dev/net/tun` device must be forwarded to it. To join a network, simply supply it on the command-line; you can supply multiple networks. ``` docker run --name myzerotier --rm --cap-add NET_ADMIN --device /dev/net/tun zerotier/zerotier:latest abcdefdeadbeef00 ``` Once joining all the networks you have provided, it will sleep until terminated. Note that in ZeroTier, joining a network does not necessarily mean you have an IP or can do anything, really. You will want to probe the control socket: ``` docker exec myzerotier zerotier-cli listnetworks ``` To ensure you have a network available before trying to listen on it. Without pre-configuring the identity, this usually means going to the central admin panel and clicking the checkmark against your zerotier identity. ### Environment Variables You can control a few settings including the identity used and the authtoken used to interact with the control socket (which you can forward and access through `localhost:9993`). - `ZEROTIER_JOIN_NETWORKS`: additional way to set networks to join. - `ZEROTIER_API_SECRET`: replaces the `authtoken.secret` before booting and allows you to manage the control socket's authentication key. - `ZEROTIER_IDENTITY_PUBLIC`: the `identity.public` file for zerotier-one. Use `zerotier-idtool` to generate one of these for you. - `ZEROTIER_IDENTITY_SECRET`: the `identity.secret` file for zerotier-one. Use `zerotier-idtool` to generate one of these for you. ### Tips - Forwarding port `:9993` to somewhere outside is probably a good idea for highly trafficked services. - Forwarding `localhost:9993` to a control network where you can drive it remotely might be a good idea, just be sure to set your authtoken properly through environment variables. - Pre-generating your identities could be much simpler to do via our [terraform plugin](https://github.com/zerotier/terraform-provider-zerotier)