我正在尝试构建一个docker-compose文件来本地部署连接到mysql服务器的NodeJS应用程序.我已经尝试了所有东西(在Stackoverflow中阅读了很多教程和一些问题),但我一直收到ECONNREFUSED错误.
这是NodeJS的Dockerfile:
##Nodejs
FROM node:latest
RUN useradd --user-group --create-home --shell /bin/false app
ENV HOME=/home/app
COPY package.json npm-shrinkwrap.json $HOME/playerground/
RUN chown -R app:app $HOME/*
USER app
WORKDIR $HOME/playerground
RUN npm cache clean && npm install --silent --progress=false
USER root
COPY . $HOME/playerground
RUN chown -R app:app $HOME/*
USER app
这是我的Mysql Dockerfile:
FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD root
ENV MYSQL_DATABASE playerground
ENV MYSQL_USER root
ENV MYSQL_PASSWORD root
这是我的docker-compose:
version: '2'
services:
db:
build: ./database
ports:
- "3307:3306"
playerground:
build:
context: .
dockerfile: Dockerfile
command: node_modules/.bin/nodemon --exec npm start
environment:
ENVIRONMENT: development
ports:
- "9090:9090"
links:
- db
volumes:
- .:/home/app/playerground
- /home/app/playerground/node_modules
另一件事是来自Nodejs的配置文件:
//Database
'development' : {
'host' : process.env.HOSTNAME || 'localhost','user' : 'root','password' : 'root','database' : 'playerground'
},//Server
'development' : {
'host' : process.env.HOSTNAME || '127.0.0.1','port' : 3000
},
你能帮助我吗?
谢谢