Skip to content

Commit

Permalink
Update docker network creation
Browse files Browse the repository at this point in the history
  • Loading branch information
evertramos committed May 13, 2021
1 parent a545f10 commit 25dde08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 7 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### @todo
- specify network mask when creating IPv4 networks
--subnet="172.17.0.0/16"
--subnet="172.17.0.0/16"

if error:

"Error response from daemon: Pool overlaps with other one on this address space"

specify a new address
20 changes: 11 additions & 9 deletions docker/docker-network-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,36 @@
#
# You must/might inform the parameters below:
# 1. Network name which should be created
# 2. [optional] (default: false) Set 'true' if IPv6 should be enabled
# 3. [optional] (default: ) Subnet for the IPV6
# 2. [optional] (default: ) Subnet for the IPV4
# - This option is required if you are activating IPv6
# 3. [optional] (default: false) Set 'true' if IPv6 should be enabled
# 4. [optional] (default: ) Subnet for the IPV6
# in the network options
#
#-----------------------------------------------------------------------

docker_network_create()
{
local LOCAL_NETWORK_NAME LOCAL_ENABLE_IPv6 LOCAL_RESULT
local LOCAL_NETWORK_NAME LOCAL_ENABLE_IPv4 LOCAL_ENABLE_IPv6 LOCAL_RESULT

LOCAL_NETWORK_NAME=${1:-null}
LOCAL_ENABLE_IPv6=${2:-false}
LOCAL_IPv6_SUBNET=${3:-"2001:db8:1:1::/112"}
LOCAL_IPv4_SUBNET=${2:-"172.17.0.0/16"}
LOCAL_ENABLE_IPv6=${3:-false}
LOCAL_IPv6_SUBNET=${4:-"2001:db8:1:1::/112"}

[[ $LOCAL_NETWORK_NAME == "" || $LOCAL_NETWORK_NAME == null ]] && echoerror "You must inform the network name to the function: '${FUNCNAME[0]}'"

[[ ! $LOCAL_ENABLE_IPv6 == "" && ! $LOCAL_ENABLE_IPv6 == null ]] && \
[[ $LOCAL_IPv6_SUBNET == "" || $LOCAL_IPv6_SUBNET == null ]] && echoerror "You must inform the network subnet for ipv6"
[[ "$LOCAL_ENABLE_IPv6" == true ]] && [[ $LOCAL_IPv6_SUBNET == "" || $LOCAL_IPv6_SUBNET == null ]] && echoerror "You must inform the network subnet for ipv6"

[[ "$DEBUG" == true ]] && echo "Creating the network '$LOCAL_NETWORK_NAME' in this server."

# Create docker network
if [[ "$LOCAL_ENABLE_IPv6" == true ]]; then
if ! docker network create $LOCAL_NETWORK_NAME --ipv6 --subnet=$LOCAL_IPv6_SUBNET; then
if ! docker network create $LOCAL_NETWORK_NAME --ipv6 --subnet=$LOCAL_IPv6_SUBNET --subnet=$LOCAL_IPv4_SUBNET; then
ERROR_DOCKER_NETWORK_CREATE=true
fi
else
if ! docker network create $LOCAL_NETWORK_NAME; then
if ! docker network create $LOCAL_NETWORK_NAME --subnet=$LOCAL_IPv4_SUBNET; then
ERROR_DOCKER_NETWORK_CREATE=true
fi
fi
Expand Down

0 comments on commit 25dde08

Please sign in to comment.