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?
you need the ip address of the host, and then to configure mysql to accept requests from another ip address(container)
Is it not possible to interact with local host, rather than using IP of it? @sdetweil
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
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
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
1 Like