• [6.10.2] /etc/rc.d/rc.docker ignores additional container networks and can't auto-start affected containers


    user12345678
    • 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!




    User Feedback

    Recommended Comments

    I have taken your code as input and added support for automatic reconnection of user defined networks.

    This will be available in the next release.

     

    Thanks for your suggestions.

     

    Link to comment

    Thank you for picking this up & incorporating it, I can get rid of my go hack that replaces the rc script at boot when this comes out.

     

    :)

     

    Many thanks!!

     

    Link to comment


    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.
    Note: Your post will require moderator approval before it will be visible.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Restore formatting

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


  • Status Definitions

     

    Open = Under consideration.

     

    Solved = The issue has been resolved.

     

    Solved version = The issue has been resolved in the indicated release version.

     

    Closed = Feedback or opinion better posted on our forum for discussion. Also for reports we cannot reproduce or need more information. In this case just add a comment and we will review it again.

     

    Retest = Please retest in latest release.


    Priority Definitions

     

    Minor = Something not working correctly.

     

    Urgent = Server crash, data loss, or other showstopper.

     

    Annoyance = Doesn't affect functionality but should be fixed.

     

    Other = Announcement or other non-issue.