javascript - Docker container nodejs connection to external mysql fail -
javascript - Docker container nodejs connection to external mysql fail -
my nodejs application connecting mysql externally, if start interactively docker run -p 49160:8080 -t -i <image>
, , run nodejs /src/server.js
manually. however, when start daemon docker run -p 49160:8080 -d <image>
, fail connect external mysql.
tried docker start <container>
, docker exec <container> nodejs /src/server.js
, same error.
tried docker start <container>
,docker attach <container>
,run nodejs /src/server.js
, works.
dockerfile:
from ubuntu re-create . /src run apt-get install nodejs run apt-get install npm run cd /src; npm install expose 8080 cmd ["nodejs","/src/server.js"]
/src/server.js:
var express = require('express'); var mysql = require('mysql'), myconnection = require('express-myconnection'); ... app.use(myconnection(mysql, { ... },'request')); ... app.get('/',function(req,res) { req.getconnection(function(err,connection) { if(err) // giving out err here, fail connect
update:
i found out cause nodejs /src/server.js
, cd /src; nodejs server.js
former give me connection error , latter works ok
so docker run -p 49160:8080 -d <image> /bin/sh -c "cd /src; nodejs server.js"
works
mark ,do have thought ?? still need output of ifconfig
? thx
ok, seems problem directory launch command. let's give seek adding in dockerfile before cmd command:
workdir /src
ps no thanks, ifconfig
no more needed.
javascript mysql node.js connection docker
Comments
Post a Comment