Skip to content

SOLUTION - Group PyArmor license on Windows Host - Run unlimited dockers in offline device #2229

@DarioMagniPLRM

Description

@DarioMagniPLRM

After reading the specific documentation https://pyarmor.readthedocs.io/en/stable/how-to/register.html#run-unlimited-dockers-in-offline-device, I encountered several problems trying to apply it to my environments (Windows host, WSL & docker desktop, Linux containers).
I read the previous open issues but did not find a working solution.
So, after several attempts, I found a working solution, which I describe below, hoping it will be useful.

Linked issues:

and more...

PyArmor Group on Windows + Docker Desktop (centralized proxy)

This guide explains how to reliably use a PyArmor Group license with Docker Desktop on Windows using the official "Run unlimited dockers in offline device" approach. It describes the initial scenario, the centralized proxy solution implemented in this repo, and the essential operational steps.

Initial scenario

  • Windows host with Docker Desktop (Linux containers), registered as an offline PyArmor device (Windows device regfile).
  • Requirement: run PyArmor inside a Docker container while reusing the host license.
  • Problem: on Docker Desktop, host.docker.internal is not in the same L3 subnet as containers; PyArmor requires an on-net (same-subnet) auth endpoint for the unlimited-dockers mode.

Adopted solution (in this project)

  1. pyarmor-auth runs on Windows using the Windows device regfile.
  2. A centralized TCP proxy (socat-based) runs in a shared Docker network pyarmor-net (172.30.0.0/24) with a fixed IP 172.30.0.10.
  3. Each application stack attaches to pyarmor-net and maps host.docker.internal -> 172.30.0.10. This makes the auth endpoint appear on-net and license checks succeed.

Repo components:

  • Substack: pyarmor-proxy/docker-compose.yml (creates pyarmor-net and starts the central proxy at 172.30.0.10)
  • Application stacks: your-app-image, your-app-image2,... (attached to pyarmor-net with extra_hosts pointing to the proxy)

Prerequisites

  • PyArmor installed on Windows and a valid Group license (activation/registration files).
  • Docker Desktop running on Windows.
  • PowerShell (pwsh) recommended as your shell.

Step-by-step

  1. Start the PyArmor auth server on Windows (using the Windows device regfile):
pyarmor-auth C:\path\to\pyarmor-device-regfile-xxxx.N.zip
# Expected: "listen container auth request on 0.0.0.0:29092"
  1. Start the centralized proxy (also creates the shared pyarmor-net if missing):

pyarmor-proxy/docker-compose.yml

FROM alpine:3.19
RUN apk add --no-cache socat
EXPOSE 29092
# Forward local 29092 to Windows host via Docker Desktop mapping
ENTRYPOINT ["socat","-d","-d","TCP-LISTEN:29092,fork,reuseaddr","TCP:host.docker.internal:29092"]
(docker network inspect pyarmor-net >/dev/null 2>&1) || docker network create --subnet=172.30.0.0/24 pyarmor-net
docker compose -f ./pyarmor-proxy/docker-compose.yml up -d --build
  1. Start an application stack (already configured to use the proxy):
docker compose -f ./your-app-image/docker-compose.yml up -d --build
  1. Register PyArmor inside the container with the Windows device regfile (if not already done there):
docker cp "C:\path\to\pyarmor-device-regfile-xxxx.N.zip" your-app-image:/
docker exec -it your-app-image bash
pyarmor reg /home/coder/project/pyarmor-device-regfile-xxxx.N.zip
pyarmor -v
  1. Quick checks
ping -c 1 host.docker.internal
curl -v telnet://host.docker.internal:29092
echo "print('hello world')" > foo.py
pyarmor gen --enable-rft foo.py

How it works (why the proxy is needed)

  • On Docker Desktop, the IP behind host.docker.internal is typically not in the same subnet as containers. PyArmor requires an on-net endpoint for unlimited-dockers.
  • The centralized proxy lives in the same Docker network as the app containers (pyarmor-net) and forwards to host.docker.internal:29092 (routed to Windows by Docker Desktop). PyArmor thus sees a peer in the same network and license verification succeeds.

Minimal example (app service)

Application stacks use a shared external network and map the host to the proxy:

services:
  app:
    image: your-app-image
    extra_hosts:
      # Map host.docker.internal to the on-net PyArmor proxy (same-subnet requirement)
      - "host.docker.internal:172.30.0.10"
    networks:
      # Attach pyarmor-net first (primary) so default route matches the host mapping
      - pyarmor-net

networks:
  pyarmor-net:
    external: true

Notes:

  • If 172.30.0.0/24 conflicts in your environment, adjust the subnet in pyarmor-proxy/docker-compose.yml and update extra_hosts in your stacks.
  • Ensure pyarmor-auth is reachable on TCP/29092 (Windows firewall rules).

Troubleshooting

  • "this license is not for this machine" during gen:

    • Verify reachability to the proxy: ping host.docker.internal, curl -v telnet://host.docker.internal:29092.
    • Ensure pyarmor-auth uses the Windows device regfile.
    • Inside the container, pyarmor -v should show a valid Group license for your product.
  • "out of license":

    • PyArmor is not registered in the container or cannot reach the auth server. Register with the correct device regfile and check connectivity.
  • Versions:

    • Keep PyArmor versions aligned between host and container (same major recommended). Aligning Python versions is not strictly required for this solution, but generally reduces runtime differences.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions