首先,我为我糟糕的英语道歉:)
我使用包含环回API,PostgreSQL数据库和其他一些服务的docker-compose来设置环境。
在这里你可以看到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", "."]
在这里你可以看到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',
},
};
当我尝试运行docker-compose时,我将获得以下输出
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)
我已经走进容器并发送了一个ping到" postgresql"它导致0%的数据包丢失 但是ping 54.201.47.166会丢失100%的数据包
搜索整个www无结果:(
请有人帮助我
答案 0 :(得分:0)
尝试为postgres服务提供一个包含container_name: postgresql
&的容器名称。然后在应用程序容器中ping postgresql
服务而不是容器的IP。确保DATABASE_HOST
与container_name
匹配。示例MEAN应用程序docker-compose file here。