- Minor
Greetings.
I posted about this in a few places hoping to gain some visibility, including here:
So I'm trying a new 'bug report' now...
The gist is that if the 'Post Arguments' field is used on a container (that is set to auto-start) to do something like '&& docker network connect...' with the intent of adding a second (or third, etc.) network to a container the rc script is unable to start the container on reboot, docker restart, etc. because it doesn't re-attach the network (after re-creating it) like it does for the main container network and since the container still references the old network id it fails with something like:
unraid rc.docker: Plex-Media-Server: Error response from daemon: network ea31527bec520a923c5c8a466c0e265b775ba66262c7613d08684c786f5de5b4 not found unraid rc.docker: Error: failed to start containers: Plex-Media-Server
My solution was to modify the rc.docker script in a hacky-way & add a loop to examine the container for additional networks and, if any are found, add them to the array that gets looped over later to re-attach.
basically I added the following:
# the loop above is based on the xml template which only defines one network - what about
# containers where someone has done docker network connect <second network> <container>?
# for those additional networks we need to cycle through them and add them to the array also
ALL_CONTAINER_NETWORKS=$(docker container inspect $CONTAINER\
--format='{{range $key, $value := .NetworkSettings.Networks}}{{$key}},
{{if $value.IPAMConfig}}
{{if $value.IPAMConfig.IPv4Address}}{{$value.IPAMConfig.IPv4Address}}{{end}}
{{if $value.IPAMConfig.IPv6Address}}{{$value.IPAMConfig.IPv6Address}}{{end}}
{{end}}
|{{end}}'\
)
# an unfortunate side-effect of spreading the command above across multiple lines (for readability) is those newlines
# sometimes end up in the final string, so take this opportunity to remove extra spaces and newlines from the result
ALL_CONTAINER_NETWORKS=${ALL_CONTAINER_NETWORKS//[ $'\n']/}
for CN in ${ALL_CONTAINER_NETWORKS//|/ }; do
AN_ADDITIONAL_CONTAINER_NETWORK=${CN%,*}
AN_ADDITIONAL_CONTAINER_IP=${CN#*,}
if [[ -n $AN_ADDITIONAL_CONTAINER_NETWORK ]] && [[ $AN_ADDITIONAL_CONTAINER_NETWORK != $THIS_NETWORK ]]; then
echo "container $CONTAINER has an additional network that will be restored: $CN" | logger -t $(basename $0)
NETRESTORE[$AN_ADDITIONAL_CONTAINER_NETWORK]="$THIS_ID,$AN_ADDITIONAL_CONTAINER_IP ${NETRESTORE[$AN_ADDITIONAL_CONTAINER_NETWORK]}"
fi
done
Immediately after line 197 (in-between the 'fi' and the 'done').
This seems to work really well and covers all the oddball situations that would otherwise be missed by either a go script hack or user script hack or some combination of that, however I admit I may have missed something.
Any chance some cleaned-up version of this could make its way into the next release?
Thanks!!
EDIT: I didn't attach diagnostics since I felt I explained things pretty well & have a solution, plus I'd have to un-do the solution in order to produce the diagnostics. However if they must be supplied let me know and I can attach. Thanks!