为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

huangapple go评论128阅读模式
英文:

Why can´t my Docker mysql Container communicate with my nodejs backend Container?

问题

I cannot figure out why my mysql container cannot reach port 4306 of my nodejs backend container.
为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

The Ports should be mapped to the right ones on the localhost.
为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

and the backend mysql database should connect to the right port on the container.
为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?.

为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

I am pretty new to Docker and the whole container and images stuff. I can reach the database on phpmyadmin on Port http://localhost:8098/ as I have mapped this port to Port 80 of the container. Also I can reach my frontend on port 3000(8080) and my backend on 3001(3001). I also tried to open the Port on the running mysql container with however even as root user of this container I don't have permission. Here are also my frontend and backend Dockerfiles.

As I am not running any frontend-framework I installed http-server npm-package to host the frontend.
It worked for a while, I dont know why, but now I just get the connection refused error.
What am I doing wrong?

英文:

I cannot figure out why my mysql container cannot reach port 4306 of my nodejs backend container.
为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

The Ports should be mapped to the right ones on the localhost.
为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

and the backend mysql database should connect to the right port on the container.
为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?.

为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

为什么我的 Docker MySQL 容器无法与我的 Node.js 后端容器通信?

I am pretty new to Docker and the whole container and images stuff. I can reach the database on phpmyadmin on Port http://localhost:8098/ as I have mapped this port to Port 80 of the container. Also I can reach my frontend on port 3000(8080) and my backend on 3001(3001). I also tried to open the Port on the running mysql container with however even as root user of this container I don´t have permission. Here are also my frontend and backend Dockerfiles.

As I am not running any frontend-framework I installed http-server npm-package to host the frontend.
It worked for a while, I dont know why, but now I just get the connection refused error.
What am I doing wrong?

答案1

得分: 2

你连接到 localhost:4306,这是您的后端容器,而不是数据库容器 db:4306。如果您更改它,您应该能够访问您的数据库。

英文:

You connect to localhost:4306, which is your backend container, not to the database container db:4306. If you change it, you should be able to access your db

huangapple
  • 本文由 发表于 2023年3月7日 15:43:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75659170.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定