Connecting to host port from Docker container

In my case I wanted to connect to a MySQL database that my laptop was SSH’d to.

# I had port forwarding in my ssh connection to fwd port 3306, the mysql port.
cat ~/.ssh/config
Host memsql
User ubuntu
LocalForward 3306

# on my laptop I start the ssh connection (use -N if you don’t actually want the ssh terminal for the connection)
ssh memsql

# On the laptop run Docker with net=host:
docker run -it –net=host ….

# Inside Docker get the IP of the host:

# Look for Gateway in output, in my case it is:
# this is the IP of your host from Docker’s perspective

# Command inside to test if Docker has access to the port on localhost:

nc 3306

# output something like

Post Tagged with , ,