Port offset
Table of contents
Introduction
Every product shifts the host ports of its features by an amount derived from its name, so several products run on one machine without collisions. The shift is the same on every run, so your ports never move.
ports adjusted 4 feature port(s) (+591)
That is product:env --merge in my_first_app, whose offset is 591.
How the offset is applied
offset = crc32(product_name.encode("utf-8")) % 1000
product:env --merge and product:build add the offset to every feature port, a numeric variable whose name ends in _HOST_PORT or contains _PORT_ONE or _PORT_TWO. A port your product sets itself, in its env file or its [tool.splent.config], is used as written. The features’ own files and your product’s ports, such as the web server’s, are never touched.
| Server | Variable | Base port | In my_first_app |
|---|---|---|---|
| A cache | REDIS_HOST_PORT |
6380 | 6971 |
| A database UI | DBUI_HOST_PORT |
8081 | 8672 |
| A mail catcher, SMTP | MAILCATCHER_SMTP_HOST_PORT |
1025 | 1616 |
| A mail catcher, web UI | MAILCATCHER_UI_HOST_PORT |
8025 | 8616 |
Declaring a port in your feature
Name the variable with a _HOST_PORT suffix, give it a base value away from common system ports in docker/.env.example, and use it in the compose file.
PROXY_HTTP_HOST_PORT=8088
ports:
- "${PROXY_HTTP_HOST_PORT}:80"
Features that run a server has the rest of the rules.
See also
product:env --mergeandproduct:build, which apply the offset