Skip to content

Instantly share code, notes, and snippets.

@mdPlusPlus
Last active June 22, 2024 13:16
Show Gist options
  • Select an option

  • Save mdPlusPlus/0f6285c6402aa4aff4aa4a9e5dfc38c0 to your computer and use it in GitHub Desktop.

Select an option

Save mdPlusPlus/0f6285c6402aa4aff4aa4a9e5dfc38c0 to your computer and use it in GitHub Desktop.
FROM ubuntu:latest
LABEL \
maintainer="mdPlusPlus" \
description="Host your own ZeroTier network controller and manage it via ztncui."
# Avoid tzdata configuration
ARG DEBIAN_FRONTEND=noninteractive
# Dependencies
## TODO Figure out how to always get latest Node.js LTS release
RUN \
apt update && \
apt install -y --no-install-recommends curl g++ git gpg gpg-agent make && \
curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
apt install -y --no-install-recommends nodejs npm ca-certificates && \
npm install -g npm && \
npm install -g node-gyp && \
curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --import ; \
apt clean && \
rm -rf /var/lib/apt/lists/*
# User (so zerotier-one is not using the reserved id 999)
RUN \
groupadd -g 2000 zerotier-one && \
useradd -u 2000 -g 2000 zerotier-one && \
mkdir -p /home/zerotier-one && \
chown -R zerotier-one:zerotier-one /home/zerotier-one
# ZeroTier-One
RUN \
if z=$(curl -s 'https://install.zerotier.com/' | gpg); then echo "$z" | bash; fi; exit 0
# ztncui
RUN \
mkdir -p /opt/ztncui && chown zerotier-one:zerotier-one /opt/ztncui && \
su zerotier-one -c "git clone https://github.com/key-networks/ztncui /opt/ztncui && \
cd /opt/ztncui/src && \
mv -v etc/default.passwd ../passwd.orig && \
echo 'HTTPS_PORT=3443' >> .env" && \
su zerotier-one -c "cd /opt/ztncui/src && npm install"
# Clean
## TODO
# Volumes
VOLUME ["/var/lib/zerotier-one/"]
VOLUME ["/opt/ztncui/src/etc/"]
# Ports
# HTTP:
#EXPOSE 3000/tcp
# HTTPS:
EXPOSE 3443/tcp
# Start
CMD \
chown -R zerotier-one:zerotier-one /var/lib/zerotier-one/ /opt/ztncui/src/etc/ && \
su zerotier-one -c "zerotier-one -U -d" && \
while [ ! -f /var/lib/zerotier-one/authtoken.secret ]; do sleep 1; done && \
chmod g+r /var/lib/zerotier-one/authtoken.secret && \
su zerotier-one -c "mkdir -p /opt/ztncui/src/etc/tls" && \
if [ ! -f /opt/ztncui/src/etc/passwd ]; then su zerotier-one -c "mv -v /opt/ztncui/passwd.orig /opt/ztncui/src/etc/passwd"; fi && \
if [ ! -f /opt/ztncui/src/etc/tls/privkey.pem ]; then su zerotier-one -c "openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:4096 -keyout /opt/ztncui/src/etc/tls/privkey.pem -out /opt/ztncui/src/etc/tls/fullchain.pem -subj '/C=XY/ST=XY/L=XY/O=XY/OU=XY/CN=XY'"; fi && \
su zerotier-one -c "cd /opt/ztncui/src && npm start"
@mdPlusPlus

Copy link
Copy Markdown
Author

@ovizii

ovizii commented Jun 15, 2020

Copy link
Copy Markdown

Would you mind also updating the docker hub image please? => https://hub.docker.com/r/mdplusplus/zerotier-network-controller-ui
I am struggling using your Dockerfile to build my own. My first try to build something on my own :-)

@mdPlusPlus

Copy link
Copy Markdown
Author

Should already be up-to-date (Updated 10 days ago)

@ovizii

ovizii commented Jun 17, 2020

Copy link
Copy Markdown

Should already be up-to-date (Updated 10 days ago)

Thanks but that is weird, I obviously checked before posting the docker hub link and asking you if you would update. Must have been the internet gremlins hiding that update from me :-)

@picolens

Copy link
Copy Markdown

Excellent. Thanks so much @mdPlusPlus.

@gusrendonb

Copy link
Copy Markdown

Hi there. This is a great tool. I'm testing it right now. One question, how do I set flow rules in the network?
Thank you

@mdPlusPlus

mdPlusPlus commented Oct 17, 2020

Copy link
Copy Markdown
Author

Not implemented in ztcui, you have to directly speak to the zerotier-one instance (I think JSON-RPC?). There was a pull request to get this feature merged into ztncui, but it was never cleanly submitted and the author has gone silent.

If anyone is willing to clean that up, I'm sure @key-networks would be willing to merge it: key-networks/ztncui#21

@ovizii

ovizii commented Jan 14, 2021

Copy link
Copy Markdown

seems the zt version of this image is still 1.4.6 - would you mind updating the image to 1.6.2 please? I am still clueless on how to use your dockerfile and build my own.

@key-networks

Copy link
Copy Markdown

https://hub.docker.com/r/keynetworks/ztncui now contains zerotier-one-1.6.2, no longer needs --cap-add=NET_ADMIN and avoids UID/GID clashes in Ubuntu.

@ovizii

ovizii commented Jan 17, 2021

Copy link
Copy Markdown

@key-networks:

so I can switch from using
image: mdplusplus/zerotier-network-controller-ui
to
image: keynetworks/ztncui:latest

as you have included all the same fixes in your image?

@key-networks

Copy link
Copy Markdown

In theory, yes. Just test and let us know how it goes.

@key-networks

Copy link
Copy Markdown

Good to back up your data beforehand.

@mdPlusPlus

Copy link
Copy Markdown
Author

@key-networks: Good to see you still working on that project!

@key-networks

Copy link
Copy Markdown

@mdPlusPlus: Thanks for your help with identifying the previous issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment