Skip to content

Fix issues with Docker bridge networks#9

Open
dsnopek wants to merge 3 commits intojuli3nk:masterfrom
dsnopek:bridge
Open

Fix issues with Docker bridge networks#9
dsnopek wants to merge 3 commits intojuli3nk:masterfrom
dsnopek:bridge

Conversation

@dsnopek
Copy link
Copy Markdown

@dsnopek dsnopek commented Nov 9, 2016

We have a bunch of services running on Docker bridged networks via docker-compose. The current script doesn't setup all the iptables rules exactly like the Docker daemon, which would cause everything to break everytime 'csf' got restarted. This PR contains the fixes that worked for me!

I used iptables-save to dump the rules that get setup by starting CSF then the Docker daemon without this script. Then I added the script, restarted CSF and iptables-save to dump the rules generated by this script, and compared them via diff - the only difference with my PR is the order that containers or networks are added, which is really just a difference in the order when looping - in everyway that matters the result is the same in our testing!

@ghost
Copy link
Copy Markdown

ghost commented Nov 9, 2016

Good! I will look at it. Thanks

Comment thread docker.sh Outdated
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
Copy link
Copy Markdown

@ghost ghost Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why changing sh for bash?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, this is a thing I need locally because /bin/sh is dash - I didn't mean for it to end up in the PR. I'll revert this change and keep it in a local branch

Comment thread docker.sh
if [ $? -eq 0 ]; then
iptables -A DOCKER-ISOLATION -i ${int_in} -o ${int_out} -j DROP
fi
iptables -A DOCKER-ISOLATION -i ${int_in} -o ${int_out} -j DROP
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to remove the condition?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, first of all, writing it in two parts like that seems to cause csf to stop running the whole script. If you put it directly in the if it wouldn't do that:

if iptables -C -A DOCKER-ISOLATION -i ${int_in} -o ${int_out} -j DROP > /dev/null 2>&1; then
        iptables -A DOCKER-ISOLATION -i ${int_in} -o ${int_out} -j DROP
fi

... however, it always fails for me and so the rule is never added - I'm not sure why. But removing the if altogether leads to the rules matching what Docker would do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which version of iptables do you have?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ sudo iptables --version
iptables v1.4.21

Copy link
Copy Markdown

@mis4s mis4s Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm, if you are using docker-compose use version @dsnopek. But you need docker version ~1.12.

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants