Skip to content

Instantly share code, notes, and snippets.

@cristiroma
Created February 12, 2018 11:41
Show Gist options
  • Save cristiroma/406a3fc0f55f99576a4b293def2f4067 to your computer and use it in GitHub Desktop.
Save cristiroma/406a3fc0f55f99576a4b293def2f4067 to your computer and use it in GitHub Desktop.
Connect from docker container to host service (mysqld)
# docker-compose.yml - creates a new network bridge
# listed in `docker network ls`.
# Note the name, i.e: `br-f60327d77bc2`
services:
tomcat:
image: tomcat:7.0
networks:
- dockernet
networks:
dockernet:
driver: bridge
ipam:
config:
- subnet: 192.168.0.0/24
gateway: 192.168.0.1
# Add iptables firewall rule to allow connection to MySQL running on host system:
# Note: MySQL must listen on all interfaces: 0.0.0.0:3306!
# Use other iptables rule to limit external traffic to MySQL
-A INPUT -p tcp -m state --state NEW -m tcp -i br-f60327d77bc2 --dport 3306 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment