このエラーはECONNREFUSEDと同じです。しかし、実装方法が異なる場合、ここで別の質問をします。ここでnodeJSのポストグルにドコラー作成ECONNREFUSEDを設定
はここdocker-compose.yml
ファイル
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
は私が知っているストアデータベース情報
{
"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"
}
}
そしてDB
import database from '../../config/database.json'
const sequelize = new Sequelize(dbConfig.database, dbConfig.username, dbConfig.password, dbConfig)
を接続するためにSequelizeを使用するために使用されるdatabase.json
ファイルです私がコンテナでアプリケーションを実行すると、両方ではありませんロカホストではhost
を変更する必要がありますが、ここでどのように変更することができます。私はhost
からpostgres
にアップデートしました。それは動作しますが、解決策は私が探したいものではありません。
ところで、ここでどのようにDBを作成できますか?
postgres_1 | FATAL: database "starflow" does not exist
どのような解決策が必要ですか? 'ホスト'を 'postgres'に変更するのが最善の方法ですから –
ドッカー用の新しい環境を作る必要はありますか?ローカルでサーバーを実行するための開発のみを使用します。 –
Dockerは新しい環境で動作します。コンテナが初めて実行されているときにその環境を設定する必要があります。 – Ayushya