Sunday, 7 May 2017

Express does not run on docker, but on localhost

I am struggling on deploying my backend to the docker container. I found out, that my ploblem is the express framework. First of all, I must say, that everything works on my localhost fine. But when I deploy my app to the server I am getting the 503 Error (service is not availible). If I initialize my app NOT via express, than everything is also working inside the docker container. So what could be the problem? Here is my docker code:

FROM node:alpine


RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app

EXPOSE 9080

CMD [ "npm", "start" ]

And here is my node code:

var express = require('express');
var app = express();

app.listen(process.env.PORT || 9080);

app.get('/test', function(req, res){
    res.send("hi");
});

And here is my package.json:

{
   "name": "server",
   "version": "1.0.0",
   "description": "Backend Shareco",
   "main": "index.js",
   "scripts": {
      "start": "node index.js"
   },
   "author": "Shareco GmbH",
   "license": "ISC",
   "dependencies": {
       "multer": "1.1.0",
       "mysql": "^2.13.0"
   }
}

Why does it not work? Would be thankful for any help.

Kind regards,

Andrej



via Andrej Tihonov

No comments:

Post a Comment