Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically choose the Docker network subnet #4879

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion generate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down