Dynamically choose the Docker network subnet

This commit is contained in:
Abbas 2022-12-01 15:50:33 +03:30 committed by GitHub
parent ff4f2ae0b6
commit 5c2ab9fc9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -158,6 +158,24 @@ if [ ! -z "${MAILCOW_BRANCH}" ]; then
git_branch=${MAILCOW_BRANCH}
fi
if [[ $(docker network ls -q \
| xargs docker network inspect --format $'{{range .IPAM.Config}}{{.Subnet}}\n{{end}}' \
| grep -qsP '172\.22.*' )$? \
-eq 0 ]]; then
max_octet=$(docker network ls -q \
| xargs -I {} docker network inspect {} --format $'{{range .IPAM.Config}}{{.Subnet}}\n{{end}}' \
| grep -P '172\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]+$' \
| sort \
| tail -n 1 \
| sed -e 's~\(172\)\.\([0-9]\+\).*~\2~g')
DOCKER_NETWORK="172.$(($max_octet+1)).1"
else
DOCKER_NETWORK='172.22.1'
fi
git fetch --all
git checkout -f $git_branch
@ -361,7 +379,7 @@ LOG_LINES=9999
# Internal IPv4 /24 subnet, format n.n.n (expands to n.n.n.0/24)
# Use private IPv4 addresses only, see https://en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses
IPV4_NETWORK=172.22.1
IPV4_NETWORK=${DOCKER_NETWORK}
# Internal IPv6 subnet in fc00::/7
# Use private IPv6 addresses only, see https://en.wikipedia.org/wiki/Private_network#Private_IPv6_addresses