[英]How to solve docker-compose docker mysql ECONNREFUSED?
I have the following docker compose:我有以下 docker 撰写:
services:
server:
container_name: server
build:
context: ./BE
dockerfile: ./Dockerfile.prod
depends_on:
- mysql
environment:
MYSQL_HOST_IP: mysql
ports:
- 4000:4000
links:
- mysql
mysql:
image: mysql:latest
container_name: mysqldb
cap_add:
- SYS_NICE # CAP_SYS_NICE
# container_name: my_very_special_server
ports:
- 3307:3306
volumes:
- ./DbScripts/DumpTodoOnly.sql:/docker-entrypoint-initdb.d/DumpTodoOnly.sql
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_DATABASE: todo
MYSQL_ROOT_PASSWORD: password!
MYSQL_PASSWORD: password!
healthcheck:
test: "mysql -uroot -p$MYSQL_ROOT_PASSWORD content -e 'select 1'"
interval: 1s
retries: 120
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: dev_pma
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3307
PMA_ARBITRARY: 1
restart: always
ports:
- 8183:80
client:
container_name: FE
build:
context: ./FE
dockerfile: ./Dockerfile.prod
ports:
- 3000:3000
environment:
- CHOKIDAR_USEPOLLING=true
tty: true
volumes:
db_data:
When i run: docker-compose up -d --build
当我运行时:
docker-compose up -d --build
Everything builds without errors.一切都没有错误。
I viste my php admin: http://localhost:8183/index.php?route=/&route=%2F我访问我的 php 管理员:http://localhost:8183/index.php?route=/&route=%2F
And I can see that my two tables are created:我可以看到我的两个表已创建:
Problem:问题:
On the server I have a route http://localhost:4000/api/create在服务器上我有一条路线 http://localhost:4000/api/create
Which basically take in a body param that should add a todo to the todos table.它基本上接受了一个 body 参数,该参数应该将一个 todo 添加到 todos 表中。
but when using postman I get:但是当使用 postman 我得到:
{
"status": "error",
"statusCode": 500,
"message": {
"errno": "ECONNREFUSED",
"code": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 3306,
"fatal": true
}
}
I thought that ny db image did not get build in time so I added a healtcheck in the compose file:我认为 ny db image 没有及时构建,所以我在 compose 文件中添加了一个 healtcheck:
healthcheck:
test: "mysql -uroot -p$MYSQL_ROOT_PASSWORD content -e 'select 1'"
interval: 1s
retries: 120
and on the server image:在服务器图像上:
depends_on:
mysql:
condition: service_healthy
But when I wanted to build the compose file I got:但是当我想构建我得到的撰写文件时:
ERROR: for server Container "a7916ff588af" is unhealthy.错误:服务器容器“a7916ff588af”不健康。 Encountered errors while bringing up the project
启动项目时遇到错误
What am I missing?我错过了什么?
Took me a while to update this question.花了我一段时间来更新这个问题。
@Phil was correct. @Phil 是对的。 I needed to add the image name on my sql configuration in node express rather than the ip.
我需要在 node express 中的 sql 配置中添加图像名称,而不是 ip。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.