I’m trying to connect a Node.js application (using Sequelize and MySQL) to a MySQL container via Docker. The MySQL container is running, but my application is unable to establish a connection to the database. The error I’m receiving is ETIMEDOUT
when attempting to connect.
Details:
- My Node.js application is running inside a Docker container.
- The MySQL container is set up using Docker Compose and is accessible (I can see that it’s running).
- The database container is named
db
, and the database isblog_db
with the root passwordpHIdianARB
. - When I try to test the database connection using a simple Node.js script (
mysql2
), the connection times out. - I’ve confirmed that the MySQL container is up and running, and I can connect to it manually from inside the application container using the
mysql
client. - I’ve checked my
docker-compose.yml
and.env
files, and they seem to be correct. The application service depends on the database, and the network configuration appears fine.
Error Message:
arduino
Copiar código
Error: connect ETIMEDOUT
at Connection._handleTimeoutError
at listOnTimeout
at process.processTimers
Steps Taken:
- Verified the
docker-compose.yml
file to ensure proper network setup and dependencies. - Tried connecting to MySQL from inside the container with the
mysql
client and succeeded. - Checked MySQL logs for any issues.
- Ensured correct environment variables (
DB_HOST=db
,DB_USER=root
, etc.) are set.
Question:
What could be causing the ETIMEDOUT
error when attempting to connect from my Node.js application container to the MySQL container, and how can I resolve it?