Docker: Access Host Ports

Sometimes you may want to access ports on your host from within a container. This is easily done by looking a the destination of the network gateway 0.0.0.0:

user@docker $ netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'
user@docker $ 172.17.0.1 #your address may differ

You can now use this address. For example if the host were running a web server, you could access it from within a container with

user@docker $ curl 172.17.0.1

If netstat is installed via net-tools ($ apt install net-tools).

 

Leave a Reply

Your email address will not be published. Required fields are marked *