has anyone successfully dockerize a Loopback-4 (lb4) app? I set up an lb4 based app and am trying to dockerize it, but although the Docker seems to be running the app, it's not showing on my localhost.
The steps I did:
- Setup Loopback 4 based app locally
- Create Dockerfile (code here)
- (cd into the dir where Dockerfile is) Build: docker build -t lb4 .
- Run: docker run -p 3000:3000 lb4
But, the app doesn't show up on http://localhost:3000 The output from running the container:
trip@1.0.0 prestart /usr/src/app npm run build
trip@1.0.0 build /usr/src/app lb-tsc es2017 --outDir dist
trip@1.0.0 start /usr/src/app node .
Server is running at http://127.0.0.1:3000 Try http://127.0.0.1:3000/ping
EDIT
For the sake of conserving the question, relevant code in the repo (step 2) is pasted here,
// index.js
const application = require('./dist');
module.exports = application;
if (require.main === module) {
// Run the application
const config = {
rest: {
port: +process.env.PORT || 3000,
host: process.env.HOST || 'localhost',
openApiSpec: {
// useful when used with OASGraph to locate your application
setServersFromRequest: true,
},
},
};
application.main(config).catch(err => {
console.error('Cannot start the application.', err);
process.exit(1);
});
}
As suggested by @Henry in the comment, in your index.js, change to use
To know more about the different between localhost (127.0.0.1) and 0.0.0.0, see https://superuser.com/questions/949428/whats-the-difference-between-127-0-0-1-and-0-0-0-0
PS
It's better to have
npm run build
during the build phrase for faster start at run time.