Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerized Loopback 4 app not reachable from the host

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:

  1. Setup Loopback 4 based app locally
  2. Create Dockerfile (code here)
  3. (cd into the dir where Dockerfile is) Build: docker build -t lb4 .
  4. Run: docker run -p 3000:3000 lb4

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);
  });
}
like image 225
Chip Avatar asked Dec 13 '18 10:12

Chip


1 Answers

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.

like image 52
Siyu Avatar answered Sep 20 '22 03:09

Siyu