Install ZeroTier in Proxmox Using Docker
A. What is ZeroTier
ZeroTier is a software-defined networking solution that enables the creation of secure virtual networks over the internet. ZeroTier allows devices to communicate as if they were on the same local network, regardless of their physical location. It supports various platforms, including Windows, macOS, Linux, iOS, and Android.
Key features of ZeroTier include:
- Ease of Use: It’s designed to be user-friendly, with straightforward setup and configuration.
- Cross-Platform Compatibility: Works across different operating systems and devices.
- Scalability: Can handle small to large networks efficiently.
- Security: Provides encrypted communication to ensure secure data transfer.
- Flexibility: Allows for custom network configurations and virtual LAN setups.
B. References
https://www.zerotier.com/pricing/ https://github.com/zerotier https://docs.zerotier.com/ https://www.zerotier.com/download/ https://docs.zerotier.com/docker/ https://github.com/zyclonite/zerotier-docker/blob/main/docker-compose.yml https://docker-compose.net/ryhtib https://techoverflow.net/2022/08/19/how-to-setup-zerotier-one-ztncui-using-docker-compose-in-just-2-minutes/
C.Installation
Here is a step-by-step guide to creating the necessary files, including the .env
file, create_network.sh
script, and docker-compose.yml
file.
By following these steps, you will set up ZeroTier in your Proxmox container with Docker Compose, using a dynamically generated network ID.
Step 1: Create the .env
File
-
Open the
.env
File with Nano:nano .env
-
Add Your ZeroTier API Token:
Add your ZeroTier API token to the
.env
file:ZEROTIER_API_TOKEN=your_api_token
Replace
your_api_token
with your actual ZeroTier API token. -
Save and Exit:
- Press
CTRL + X
to exit. - Press
Y
to confirm changes. - Press
Enter
to save the file.
- Press
Step 2: Create the create_network.sh
Script
-
Open the
create_network.sh
File with Nano:nano create_network.sh
-
Add the Following Script Content:
#!/bin/bash # Load the API token from the .env file source .env # Create a new network RESPONSE=$(curl -s -X POST -H "Authorization: Bearer $ZEROTIER_API_TOKEN" -H "Content-Type: application/json" -d '{}' "https://my.zerotier.com/api/v1/network") # Extract the network ID from the response NETWORK_ID=$(echo $RESPONSE | jq -r '.id') # Save the network ID to the .env file echo "ZEROTIER_NETWORK_ID=$NETWORK_ID" >> .env # Print the network ID echo "Network ID: $NETWORK_ID"
-
Save and Exit:
- Press
CTRL + X
to exit. - Press
Y
to confirm changes. - Press
Enter
to save the file.
- Press
-
Make the Script Executable:
chmod +x create_network.sh
Step 3: Run the Script to Generate the Network ID
-
Install
jq
(if not already installed):sudo apt install -y jq
-
Run the Script:
./create_network.sh
This script will create a new ZeroTier network, save the network ID to the
.env
file, and print the network ID.
Step 4: Create the docker-compose.yml
File
-
Open the
docker-compose.yml
File with Nano:nano docker-compose.yml
-
Add the Following Content:
version: '3.8' services: zerotier-one: image: zerotier/zerotier-scratch container_name: zerotier-one environment: - ZEROTIER_NETWORK_ID=${ZEROTIER_NETWORK_ID} - ZEROTIER_API_TOKEN=${ZEROTIER_API_TOKEN} volumes: - zerotier-one-data:/var/lib/zerotier-one network_mode: "host" volumes: zerotier-one-data: env_file: - .env
-
Save and Exit:
- Press
CTRL + X
to exit. - Press
Y
to confirm changes. - Press
Enter
to save the file.
- Press
Step 5: Start the Docker Compose
-
Run Docker Compose:
docker-compose up -d
This command will start the ZeroTier service in detached mode using the network ID generated by the script and stored in the .env
file.
Summary
-
Create the
.env
File:nano .env
Add your ZeroTier API token.
-
Create the
create_network.sh
Script:nano create_network.sh
Add the script content and make it executable:
chmod +x create_network.sh
-
Run the Script:
./create_network.sh
-
Create the
docker-compose.yml
File:nano docker-compose.yml
Add the Docker Compose content.
-
Start Docker Compose:
docker-compose up -d