title: nodejs api running within container can not connect to server
body: <p>I have an api app build with nodejs which connect to a remote PostGresql database. It is working okay when running it using npm.</p>
  <p>I tried to build this api as docker image and run it. After running this same api app inside a docker container, the api app can no longer communicate with the PostgreSQL database.</p>
  <p><strong>ENV</strong></p>
  <ul>
  <li>Mac 10.15.7</li>
  <li>Docker 19.03.13</li>
  </ul>
  <p><strong>TRIED</strong></p>
  <ul>
  <li><code>docker run -p 8080:3000 &lt;image&gt;</code></li>
  <li><code>docker run -p 80:3000 --network=&quot;host&quot; &lt;image&gt;</code></li>
  </ul>
  <p><strong>CONSOLE</strong></p>
  <pre><code>&gt; nsm-api@0.0.1 start:dev /
  &gt; nodemon --config nodemon.json
  
  [nodemon] 2.0.6
  [nodemon] to restart at any time, enter `rs`
  [nodemon] watching path(s): src/**/*
  [nodemon] watching extensions: ts
  [nodemon] starting `TZ=utc node --inspect=127.0.0.1:9223 -r ts-node/register -- src/main.ts`
  Debugger listening on ws://127.0.0.1:9223/a8f5022e-be72-43ac-b1f7-b0487aaf370b
  For help, see: https://nodejs.org/en/docs/inspector
  [Nest] 41   - 11/26/2020, 7:56:44 AM   [NestFactory] Starting Nest application...
  [Nest] 41   - 11/26/2020, 7:56:44 AM   [InstanceLoader] AppModule dependencies initialized +145ms
  [Nest] 41   - 11/26/2020, 7:56:44 AM   [InstanceLoader] TypeOrmModule dependencies initialized +1ms
  [Nest] 41   - 11/26/2020, 7:56:44 AM   [InstanceLoader] MailerModule dependencies initialized +1ms
  [Nest] 41   - 11/26/2020, 7:56:44 AM   [InstanceLoader] HttpModule dependencies initialized +1ms
  [Nest] 41   - 11/26/2020, 7:56:44 AM   [InstanceLoader] MailerCoreModule dependencies initialized +1ms
  [Nest] 41   - 11/26/2020, 7:56:46 AM   [TypeOrmModule] Unable to connect to the database. Retrying (1)... +1979ms
  Error: EPERM: operation not permitted, scandir '/proc/1/map_files/559c210e0000-559c216d0000'
      at Object.readdirSync (fs.js:790:3)
      at GlobSync._readdir (/node_modules/glob/sync.js:288:41)
      at GlobSync._readdirInGlobStar (/node_modules/glob/sync.js:267:20)
      at GlobSync._readdir (/node_modules/glob/sync.js:276:17)
      at GlobSync._processReaddir (/node_modules/glob/sync.js:137:22)
      at GlobSync._process (/node_modules/glob/sync.js:132:10)
      at GlobSync._processGlobStar (/node_modules/glob/sync.js:380:10)
      at GlobSync._process (/node_modules/glob/sync.js:130:10)
      at GlobSync._processGlobStar (/node_modules/glob/sync.js:383:10)
      at GlobSync._process (/node_modules/glob/sync.js:130:10)
  ^Cnpm ERR! code ELIFECYCLE
  npm ERR! errno 143
  npm ERR! nsm-api@0.0.1 start:dev: `nodemon --config nodemon.json`
  npm ERR! Exit status 143
  npm ERR! 
  npm ERR! Failed at the nsm-api@0.0.1 start:dev script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-11-26T07_56_50_252Z-debug.log
  </code></pre>
  <p><strong>Dockerfile</strong></p>
  <pre><code># Use the official image as a parent image.
  FROM node:10-alpine
  
  # Set the working directory.
  WORKDIR .
  
  # Copy the file from your host to your current location.
  COPY package.json .
  
  # Run the command inside your image filesystem.
  RUN npm install
  
  # Add metadata to the image to describe which port the container is listening on at runtime.
  EXPOSE 3000
  
  # Run the specified command within the container.
  CMD [ &quot;npm&quot;, &quot;run&quot;, &quot;start:dev&quot; ]
  
  # Copy the rest of your app's source code from your host to your image filesystem.
  COPY . .
  </code></pre>
  <p><strong>Database Connection</strong></p>
  <p>I use a .env file to add database credentials and host so that the app can use to connect.</p>
  <pre><code>POSTGRES_HOST=****
  POSTGRES_PORT=***
  POSTGRES_USER=****
  POSTGRES_PASSWORD=****
  POSTGRES_DATABASE=postgres
  PORT=3000
  MODE=PROD
  RUN_MIGRATIONS=true
  SECRET_KEY=scretkey
  </code></pre>
  <hr />
  <p><strong>Edit:</strong> I have also tried with the <code>sudo</code> command, but that did not help.</p>