简体   繁体   中英

Loopback Postgres in Docker-compose environment

first of all i apologize for my bad English :)

I've tied to set up an environment with docker-compose containing a loopback API, a PostgreSQL database and several other services.

Here you can see the docker-compose.yml

version: "2.1"
services:
  postgresql:
    image: postgres:9.6
    restart: always
    environment:
      - "COMPOSE_HTTP_TIMEOUT=200000"
      - "POSTGRES_USER=root"
      - "POSTGRES_PASSWORD=root"
      - "POSTGRES_DB=hh"
  backend:
    image: tyrex/backend
    restart: always
    stdin_open: true
    tty: true
    environment:
      - "API_BASE_PATH=/api"
      - "HOST_NAME=haaye-henricus.de"
      - "PORT=3000"
      - "DATABASE_HOST=postgresql"
      - "DATABASE_PORT=5432"
      - "DATABASE_NAME=hh"
      - "DATABASE_USER=root"
      - "DATABASE_PASSWORD=root"
      - "DEBUG_DATABASE_CONNECTOR=true"
    ports:
      - "3000:3000"
    command: ["./wait-for-it.sh", "postgresql:5432", "--", "node", "."]

Here you can see the datasources.local.js

  // Copyright IBM Corp. 2014,2015. All Rights Reserved.
  // Node module: loopback-example-offline-sync
  // This file is licensed under the MIT License.
  // License text available at https://opensource.org/licenses/MIT

  'use strict';

  var DATABASE_HOST = process.env.DATABASE_HOST || 'localhost';
  var DATABASE_USER = process.env.DATABASE_USER || 'root';
  var DATABASE_PASSWORD = process.env.DATABASE_PASSWORD || 'root';
  var DATABASE_PORT = process.env.DATABASE_PORT || '5432';
  var DATABASE_NAME = process.env.DATABASE_NAME || 'hh';
  var DEBUG_DATABASE_CONNECTOR = process.env.DEBUG_DATABASE_CONNECTOR || false;
  var FILES_DIRECTORY = process.env.FILES_DIRECTORY || './storage';

  console.log('Database Url', 'postgresql://' + DATABASE_USER + ':' + DATABASE_PASSWORD + '@' + DATABASE_HOST +  ':' + DATABASE_PORT  + '/' + DATABASE_NAME);

  console.log('New Build');

  module.exports = {
    'db': {
      'name': 'db',
      'connector': 'memory',
    },
    'postgresql': {
      'url': 'postgresql://' + DATABASE_USER + ':' + DATABASE_PASSWORD + '@' + DATABASE_HOST +  ':' + DATABASE_PORT  + '/' + DATABASE_NAME,
      'debug': DEBUG_DATABASE_CONNECTOR,
      'name': 'postgresql',
      'connector': 'postgresql',
    },
    'files_datasource': {
      'name': 'files_datasource',
      'connector': 'loopback-component-storage',
      'provider': 'filesystem',
      'root': FILES_DIRECTORY,
      'nameConflict': 'makeUnique',
    },
  };

When i try to run docker-compose up i'll get the following output

events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRNOTAVAIL 54.201.47.166:5432
    at Object.exports._errnoException (util.js:1050:11)
    at exports._exceptionWithHostPort (util.js:1073:20)
    at Server.setupListenHandle [as _listen2] (net.js:1243:19)
    at listenInCluster (net.js:1307:12)
    at doListen (net.js:1432:7)
    at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:10)

I've stepped into the container and sent a ping to "postgresql" it results into 0% packet lost but pinging 54.201.47.166 gets 100% packet lost

Searching the whole www results in nothing :(

Please can somebody help me

Try to give the postgres service a container name with container_name: postgresql & then ping the postgresql service instead of the container's IP in the application container. Make sure that the DATABASE_HOST matches with the container_name . Sample Example MEAN application docker-compose file here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM