I am trying to get a nodejs app to run in a container. I have followed the tutorial here: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ and it works for the example. But, I do not know how to convert my start up command "yarn start" to be triggered by server.js.
All of the examples of dockerizing a nodejs app that I have found online use this server.js approach. In the tutorial linked above the container ends up running a simple "Hello World!" example app. I have tried putting
CMD [ "yarn", "start" ]
in my Dockerfile but it does not launch the app.
This is my package.json file:
{
"name": "my-server",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "concurrently \"cd api && yarn startd\" \"cd admin && yarn startd\"",
"dev": "concurrently \"cd api && yarn dev\" \"cd admin && yarn dev\"",
"logs": "heroku logs -t",
"heroku-postbuild": "cd src/client && npm install && npm run build"
},
"devDependencies": {
"concurrently": "^4.1.0",
"nodemon": "^1.19.4",
"prettier": "2.7.1",
"prettier-plugin-apex": "1.10.0"
}
}
Question is: How do I get server.js to do the equivalent of "yarn start"?
server.js (modified to open two ports):
'use strict';
const express = require('express');
// Constants
const PORT1 = 3000;
const PORT2 = 4000;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello World from my-server');
});
app.listen(PORT1, PORT2, HOST, () => {
console.log(`Running on http://${HOST}:${PORT1}`);
});
Thank you!