Hi! I want to have two shares, each from a seperate docker-compose. Each has there own unique name domain and a different target.
I tried to use the same volume where .zrok is stored but then it overwrites the reserved share of the one that started first and changes it's target.
zrok backend is already reserved: stockbrood
zrok-epic-share-1 | INFO: running: zrok share reserved stockbrood --override-endpoint http://host.docker.internal:3000 --headless
I also tried to use a different volume and keep things seperate but then it tries to enable the environment with the same key cause both .env have the same ZROK_ENABLE_TOKEN. I need to enable the environment so that it creates the .zrok folder in the volume but it can't create it cause it can't execute zrok enable twice.
- Using Zrok on docker for multiple services - #14 by stefanadelbert.
Here they used different targets and the same volume in one compose file. I was wondering if I use seperate compose files but keep the same volume and that command, that it could maybe work. - Zrok: How Do I Run Multiple Proxies Using as a Linux Service? - #20 by zrokooz.
Here they mentioned the use of seperate linux services but nothing about docker.
I wonder if it is possible to have seperate state directories of different shares in docker. Currently it fills the state directory with the zrok enable command but this can't be run twice with the same ZROK_ENABLE_TOKEN (I think or at least it gives an error that there was a problem enabling the environment).
[EDIT]
I got it working with customising the zrok-share.bash locally.
I made my reserved.json support multiple reserved shares in one enabled environment.
{
"shares": [
{
"token": "stockbrood",
"target": "http://host.docker.internal:80",
"frontend_endpoints": [
"https://stockbrood.share.zrok.io"
]
}
]
}
instead of
{"token":"stockbrood","frontend_endpoints":["https://stockbrood.share.zrok.io"]}
The key logic that checks for existing shares:
EXISTING_SHARES=$(jq -r '.shares[]?.target' ~/.zrok/reserved.json 2>/dev/null)
FOUND_SHARE=false
while IFS= read -r target; do
if [[ "${target}" == "${ZROK_TARGET}" ]]; then
FOUND_SHARE=true
ZROK_RESERVED_TOKEN=$(jq -r --arg target "${ZROK_TARGET}" '.shares[] | select(.target == $target) | .token' ~/.zrok/reserved.json)
The part that adds new shares to the array instead of overwriting:
jq --arg token "${NEW_TOKEN}" \
--arg target "${ZROK_TARGET}" \
--argjson endpoints "${NEW_ENDPOINTS}" \
'.shares += [{"token": $token, "target": $target, "frontend_endpoints": $endpoints}]' \
~/.zrok/reserved.json