elmerfds / rebuild-dndc

Re-create containers that use another container's network stack (i.e. routing container traffic through a VPN container)
GNU General Public License v3.0
22 stars 9 forks source link

Using a custom docker network doesn't rebuild containers #61

Closed humaintenance closed 1 year ago

humaintenance commented 1 year ago

I'm trying to utilize a custom docker network, and put the master container and rebuild-dndc inside it, which results in containers not being rebuilt.

I believe I see why, that being when container is in a custom network the endpointID is nested further when inspected, so when running docker inspect $mastercontname --format="{{ .NetworkSettings.EndpointID }}" no value is returned. You'd have to instead run docker inspect $mastercontname --format="{{ .NetworkSettings.Networks.CustomNetworkName.EndpointID }}"

Is there a way that I can achieve what I'm trying to do without forking and changing the script?

elmerfds commented 1 year ago

What's the use case of running the rebuild-dndc container under the custom network?

elmerfds commented 1 year ago

@humaintenance hopefully @Lanjelin 's PR has worked for you

lloydmaza commented 2 weeks ago

Coming back to this 1+ year later, I think the fix in https://github.com/elmerfds/rebuild-dndc/pull/63 resolves the issue on startup, but misses the same fix on subsequent runs. Note that the query here is missing the custom_network variable.

I do not have permissions to push to the repo, but I've tested this patch on my setup and it seems to work just fine!

diff --git a/Rebuild-DNDC/Rebuild-DNDC.sh b/Rebuild-DNDC/Rebuild-DNDC.sh
index 7d347ad..19f8aea 100644
--- a/Rebuild-DNDC/Rebuild-DNDC.sh
+++ b/Rebuild-DNDC/Rebuild-DNDC.sh
@@ -134,7 +134,12 @@ first_run()
     then
         printf "A. SKIPPING: FIRST RUN SETUP\n" 
         was_run=0
-        getmastercontendpointid=$(docker inspect $mastercontname --format="{{ .NetworkSettings.EndpointID }}")
+        if [[ -z "$custom_network" || "$custom_network" = "false" ]]
+        then
+            getmastercontendpointid=$(docker inspect $mastercontname --format="{{ .NetworkSettings.EndpointID }}")
+        else
+            getmastercontendpointid=$(docker inspect $mastercontname --format="{{ .NetworkSettings.Networks.${custom_network}.EndpointID }}")
+        fi
         currentendpointid=$(<$mastercontepfile_loc/mastercontepid.tmp)      
     fi
 }

Please consider opening a follow up PR to apply this fix.

Edit: I'm new to OSS contribution and didn't realize I could get my own PR stood up. That's up here now: https://github.com/elmerfds/rebuild-dndc/pull/70