Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to fix Docker iptables on Synology NAS
#!/bin/bash
currentAttempt=0
totalAttempts=10
delay=15
while [ $currentAttempt -lt $totalAttempts ]
do
currentAttempt=$(( $currentAttempt + 1 ))
echo "Attempt $currentAttempt of $totalAttempts..."
result=$(iptables-save)
if [[ $result =~ "-A DOCKER -i docker0 -j RETURN" ]]; then
echo "Docker rules found! Modifying..."
iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL ! --dst 127.0.0.0/8 -j DOCKER
echo "Done!"
break
fi
echo "Docker rules not found! Sleeping for $delay seconds..."
sleep $delay
done
@pedrolamas

This comment has been minimized.

Copy link
Owner Author

@pedrolamas pedrolamas commented Aug 18, 2020

  • Open DSM on your NAS
  • Open Control Panel and click on Task Scheduler
  • Click Create button, Triggered Task, User defined script
  • Give it a name, select "root" for User and "Boot-up" for Event, tick Enabled
  • Click Task Settings, paste the above script on the User-defined script
  • Click OK button and you're done!

The script will run after every reboot and should survive any updates of DSM!

@soflane

This comment has been minimized.

Copy link

@soflane soflane commented Nov 4, 2020

I don't know you but I already love you!
Thanks for the fix, you saved my night !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.