Dieser Fehler ist der gleiche mit ECONNREFUSED. Aber die Implementierung ist anders, dann werde ich hier eine andere Frage stellen. Hierdocker-komponieren ECONNREFUSED für Postgres auf nodeJS
ist die docker-compose.yml
Datei
version: '3'
services:
server:
build:
context: .
volumes:
# Mounts the project directory on the host to /app inside the container,
# allowing you to modify the code without having to rebuild the image.
- .:/app
# Just specify a path and let the Engine create a volume.
# Data present in the base image at the specified mount point will be copied
# over to the new volume upon volume initialization.
# node_modules from this new volume will be used and not from your local dev env.
- /app/node_modules/
# Expose ports [HOST:CONTAINER}
ports:
- "4040:4040"
# Set environment variables from this file
env_file:
- .env
# Overwrite any env var defined in .env file (if required)
environment:
- NODE_ENV=development
# Link to containers in another service.
# Links also express dependency between services in the same way as depends_on,
# so they determine the order of service startup.
links:
- postgres
postgres:
image: "postgres:9.6"
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: 123456
POSTGRES_USER: postgres
POSTGRES_DB: postgres
Hier ist die database.json
-Datei, die ich verwendet Datenbank zum Speichern von Informationen
{
"development": {
"username": "postgres",
"password": "123456",
"database": "mydb",
"host": "127.0.0.1",
"dialect": "postgres",
"pool": {
"max": 100,
"min": 0,
"idle": 10000
}
},
"test": {
"username": "postgres",
"password": "123456",
"database": "mytestdb",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"username": "postgres",
"password": "123456",
"database": "mydb",
"host": "127.0.0.1",
"dialect": "postgres"
}
}
Und Sequelize verwenden, um DB zu verbinden
import database from '../../config/database.json'
const sequelize = new Sequelize(dbConfig.database, dbConfig.username, dbConfig.password, dbConfig)
Ich weiß, Wenn ich Anwendungen in Containern starte, sind das nicht beide auf locahost muss ich dann host
ändern, aber wie kann ich hier ändern. Ich arbeitete um Update host
zu postgres
. Es funktioniert, aber die Lösung ist nicht das, was ich finden möchte.
Übrigens, wie kann ich hier DB erstellen.
postgres_1 | FATAL: database "starflow" does not exist
Also welche Lösung willst du? Weil "Host" zu "Postgres" wechseln ist der beste Weg –
Muss ich eine neue Umgebung für Docker erstellen?. Ich möchte nur die Entwicklung für den lokalen Server verwenden. –
Docker wird in einer neuen Umgebung ausgeführt. Und Sie müssen diese Umgebung konfigurieren, wenn der Container zum ersten Mal ausgeführt wird. – Ayushya