Docker - 错误:连接 ECONNREFUSED 127.0.0.1:3306

时间:2021-05-28 09:26:38

标签: mysql node.js docker econnrefused

我创建了一个 NodeJS 应用程序并构建了一个图像并运行它。在那个容器应用程序中,我试图从 //when a sub country is selected DropdownButton<String>( value: _chosenSubCounty, //elevation: 5, style: TextStyle(color: Colors.black), items: <String>['Mvita', 'Tudor', 'Kisauni'].map<DropdownMenuItem<String>>((String value) { return DropdownMenuItem<String>( value: value, child: Text(value, style: TextStyle( color: Colors.black, fontSize: 16, fontWeight: FontWeight.w600), ), ); }).toList(), hint: Text( "Sub-County", style: TextStyle( color: Colors.black, fontSize: 16, fontWeight: FontWeight.w600), ), onChanged: (String value) { setState(() { _chosenSubCounty = value; volunteers = volunteers.where((element) => element.sub_county.contains(_chosenSubCounty)).toList(); }); }, ), 访问 MySQL 数据库(MySQL 在 localhost 中)。但是,当我尝试访问它时,出现以下错误

enter image description here

我从 StackOverflow 和其他资源中寻找了很多解决方案。但是,无法解决问题。即使我尝试使用下面的方法从所有主机授予用户 root 访问权限

host

我仍然面临同样的问题。

Docker 文件:

CREATE USER 'root'@'%' IDENTIFIED BY 'passw0rd';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

你能帮我解决这个问题吗?

谢谢...

编辑:

ormconfig.json

FROM node:14
WORKDIR /usr/testapp
COPY package*.json ./
RUN npm install && npm install typescript -g
COPY . .
RUN tsc
CMD [ "node", "./dist/app.js" ]

构建和运行容器的命令:

{
   "type": "mysql",
   "host": "localhost",
   "port": 3306,
   "username": "root",
   "password": "passw0rd",
   "database": "hostelme",
   "synchronize": true,
   "logging": false,
   "entities": [
      "src/entity/**/*.ts"
   ],
   ...
}

0 个答案:

没有答案