Docker Community Forums

Share and learn in the Docker community.

[Solved] How to interact with other ports of host

(Danimvijay) #1

I am running a nodejs container in ubuntu. mySQL is available in same server in default port(3306). I would like my Express API within the nodejs container to interact with mySQL available on the host.

How can I achieve this?

Or is it necessary to run mySQL in another container and bridge it?

(Sam) #2

you need the ip address of the host, and then to configure mysql to accept requests from another ip address(container)

(Danimvijay) #3

Is it not possible to interact with local host, rather than using IP of it? @sdetweil

(Sam) #4

localhost means 'here’
inside the container, localhost means inside the container, NOT the docker host.

when u start the container, you could use the --add-host name:ipaddress
to inject a name for the docker host into the containers /etc/hosts file so you can use a name

(Danimvijay) #5

OK. That’ll do for now. Thinking of setting up a mysql container along with the project. I should use volumes to persist data, right?

Thanks, anyway :+1:

(Sam) #6

if you need to persist data, then you need to keep it outside the container.
using a volume to map the container folder onto a docker host folder is the right way