Hello everyone,
I am using docker with ignition and mysql
my mysql
i
but in the gateway when I create a connection with mysql says this:
and the error details says:
Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
I can use my connection in mysql and I can do selects to my database
I forgot to add where I am creating the image for mysql, myabe is from here
@Esme_Lopez Your mapping port 3306 inside docker to an external port of 3307. Because ignition is inside docker on the docker internal network your connection string should have the port of 3306. Try changing this to
jdbc:mysql://localhost:3306/test_db
1 Like
In this case, jdbc:mysql://localhost:3307/test_db
inside of your Ignition container points to localhost in the container, not your host machine (where you're publishing the port 3307
to connect into the mysql container's 3306
. Since MySQL isn't running alongside Ignition within the same container, there is nothing listening on localhost:3306
from Ignition's network context.
Since these are standalone containers, they're likely bound to the default bridge
network managed by Docker. This network doesn't do any name-based DNS resolution like other bridge networks do (such as those created by a Docker Compose stack). This means that you'll want to "loopback" to your host from within the container. Try the following:
jdbc:mysql://host.docker.internal:3307/test_db
EDIT: actually, looking at your update, it does appear that you're in a Compose stack. In this case, you should actually be able to use the following:
jdbc:mysql://database-mysql:3306/test_db
... since within the dedicated bridge network your two Compose services (i.e. containers) are attached to, you can resolve other containers by their service name, e.g. database-mysql
. Since you're connecting directly, you use the port that the container itself is listening on. At this point, you'd only be using the published port 3307
for your workbench connection from your host.
Here is a reference for more information: Explore networking features on Docker Desktop | Docker Docs
2 Likes
this worked: jdbc:mysql://database-mysql:3306/test_db
also I changed ports in my compose 3306:3306
Thank you so much for your time
Tip: we don't edit the title with "[Solved]" in it. Accepting the solution adds the solved check mark to the question on the main index and adds the "solution" right below your original post. I've removed it for you.