Skip to main content

Docker

Simple example using an interactive shell.

ZeroTier One makes ZeroTier virtual networks available as 'tap' virtual network ports. To do this inside a Docker container requires a few elevated permissions and access to the /dev/net/tun device.

Fortunately this is easy:

docker run -it --rm \
--cap-add=NET_ADMIN \
--device=/dev/net/tun ubuntu:24.04 [... command ...]

Where [... command ...] is an optional command, in the example below we'll provide /bin/bash to get an interactive shell.

You may want to also add --volume <volume-name>:/var/lib/zerotier-one to preserve container's configuration (such as Node's address) during the image upgrade.

info

NET_ADMIN is the only capability required. Older versions of this page also asked for SYS_ADMIN; that is no longer necessary.

Here's a transcript of an example session where we start a command prompt in a test container, install ZeroTier, start it (must be done manually here because the container does not run init or systemd), join a network, and ping something. Replace <network_id> with the ID of a network you have created — see Getting Started.

Starting a container with an interactive shell:

docker run -it --rm \
--cap-add=NET_ADMIN \
--device=/dev/net/tun ubuntu:24.04 /bin/bash

Then, while inside the container we install ZeroTier. The base image ships without curl, so install it first:

root@5b88595860bc:/# apt-get update && apt-get install -y curl
root@5b88595860bc:/# curl -s https://install.zerotier.com/ | bash

*** ZeroTier Service Quick Install for Unix-like Systems

[ ... snipped the supported-distribution banner ... ]

*** Detecting Linux Distribution

*** Detected Ubuntu Linux, creating /etc/apt/sources.list.d/zerotier.list

*** Installing zerotier-one package...

[ ... snipped apt install output ... ]

*** Enabling and starting ZeroTier service...

*** Package installed but cannot start service! You may be in a Docker container
*** or using a non-standard init service.

Start ZeroTier and join a network:

root@5b88595860bc:/# /usr/sbin/zerotier-one -d
root@5b88595860bc:/# /usr/sbin/zerotier-cli join <network_id>
200 join OK
root@5b88595860bc:/# /usr/sbin/zerotier-cli listnetworks
200 listnetworks
200 listnetworks <network_id> - 02:e6:10:ab:69:33 REQUESTING_CONFIGURATION PRIVATE zt0 -
root@5b88595860bc:/# /usr/sbin/zerotier-cli listnetworks
200 listnetworks
200 listnetworks <network_id> my-network 02:e6:10:ab:69:33 OK PRIVATE zt0 10.147.17.42/24

Try pinging something:

root@5b88595860bc:/# ping <some_other_zerotier_nodes_ip>

Exit

root@5b88595860bc:/# exit