Maybe this was due to the current version, but the current answer doesn ' t work on my system (Docker 0.7.2 with base Ubuntu Image).
The solution is explained this official Docker documentation.
For the Lazy ones:
EDIT/ETC/DEFAULT/UFW to change Default_forward_policy's value to "ACCEPT",
Reload with [sudo] ufw reload.
This ensures UFW forward your traffic to the Docker's bridged network (as of my current understanding of these things ...).
This fixed it for me:
UFW allow in on Docker0
Edit/etc/ufw/before.rules as follows:
In the *filter sections, after the first block of required lines, add:
# Docker rules to enable external network access from the container
# Forward traffic accross the bridge
-A ufw-before-forward-i docker0-j ACCEPT
-A ufw-before-forward-i testbr0-j ACCEPT
-A ufw-before-forward-m state--state related,established-j ACCEPT
At the end of the "file, after the" line "says COMMIT, add the following section:
*nat
:P ostrouting ACCEPT [0:0]
-A postrouting-s 172.16.42.0/8-o eth0-j Masquerade
# don ' t delete the ' COMMIT ' line or these rules won ' t be processed
COMMIT
After saving the file, restart UFW with sudo ufw disable && sudo ufw enable
(Ubuntu UFW) My Firewall is blocking network connections from the Docker container to outside