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:
But, the app doesn't show up on http://localhost:3000 The output from running the container:
[email protected] prestart /usr/src/app npm run build
[email protected] build /usr/src/app lb-tsc es2017 --outDir dist
[email protected] 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
host: '0.0.0.0',
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With