How the external app can access DB container

Hi,
I have 2 containers

  • frontend-app locates in frontend network
  • DB locates in the internal network

the frontend-app container can access DB container but i couldn’t access DB container from an external app that locates on an external machine. what should i do to make the external app can access DB container?

these the commands that i use to create these containers

Frontend-app Container:
docker container run -d --name frontend-app --network frontend   nginx:latest

DB container:
docker run -d --name database -p 3306:3306 -v /storage/data/mysql:/var/lib/mysql  --network localhost -e MYSQL_ROOT_PASSWORD=PW mysql:latest --default_authentication_plugin=mysql_native_password

Have you tried connecting to other services running on the same host? How are you connecting to the DB from the external app? Are you using the correct hostname/IP of the host?

Hi @maximization,
Have you tried connecting to other services running on the same host?

ys i can connect DB container from other app containers that in the same host. but i couldn’t connect from external machine.

How are you connecting to the DB from the external app?

i have open 3306 port in Iptables then tried to telnet on port 3306 from the external machine but not reachable
telnet Host_Public_IP 3306

I think this due to DB in private network (localhost network), there is anyway to make DB reachable from external machine without put it in bridge network.

What if you try doing -p 0.0.0.0:3306:3306 ? It’s usually the default but maybe your configuration has changed