英文:
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.
The Ports should be mapped to the right ones on the localhost.
and the backend mysql database should connect to the right port on the container.
.
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.
The Ports should be mapped to the right ones on the localhost.
and the backend mysql database should connect to the right port on the container.
.
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论