admin管理员组文章数量:1319462
I'm using docker-pose and I'm getting the following error when I try to run yarn sequelize db:migrate
in my console:
"Loaded configuration file "src/config/database.js". ERROR: getaddrinfo ENOTFOUND db"
Everything works fine, but I can't run my migrations.
Dockerfile
FROM node:alpine
WORKDIR /usr/app
COPY package.json yarn.lock ./
RUN yarn
COPY . .
EXPOSE 3000
CMD ["yarn", "dev"]
Docker-pose.yml
version: '3'
services:
api:
container_name: api
build: .
ports:
- '3000:3000'
mand: yarn dev
volumes:
- .:/usr/app
links:
- db
db:
container_name: db
image: mysql:5.7
volumes:
- ./data:/mysql/db
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: be_db
MYSQL_USER: root
MYSQL_PASSWORD: password
.env
# Database Variables
DB_HOST=db
DB_USER=root
DB_PASS=password
DB_NAME=be_db
DB_PORT:3306
/src/config/database.js
require('dotenv').config();
module.exports = {
dialect: 'mysql',
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
define: {
timestamps: false,
underscored: true,
underscoredAll: true,
},
};
OBS: If I switch the DB_HOST=db
to DB_HOST=localhost
I'm able to run my migrations but them, my container pops up this error:
code: 'ECONNREFUSED',
api | syscall: 'connect',
api | address: '127.0.0.1',
api | port: 3306,
api | fatal: true
I'm using docker-pose and I'm getting the following error when I try to run yarn sequelize db:migrate
in my console:
"Loaded configuration file "src/config/database.js". ERROR: getaddrinfo ENOTFOUND db"
Everything works fine, but I can't run my migrations.
Dockerfile
FROM node:alpine
WORKDIR /usr/app
COPY package.json yarn.lock ./
RUN yarn
COPY . .
EXPOSE 3000
CMD ["yarn", "dev"]
Docker-pose.yml
version: '3'
services:
api:
container_name: api
build: .
ports:
- '3000:3000'
mand: yarn dev
volumes:
- .:/usr/app
links:
- db
db:
container_name: db
image: mysql:5.7
volumes:
- ./data:/mysql/db
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: be_db
MYSQL_USER: root
MYSQL_PASSWORD: password
.env
# Database Variables
DB_HOST=db
DB_USER=root
DB_PASS=password
DB_NAME=be_db
DB_PORT:3306
/src/config/database.js
require('dotenv').config();
module.exports = {
dialect: 'mysql',
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
define: {
timestamps: false,
underscored: true,
underscoredAll: true,
},
};
OBS: If I switch the DB_HOST=db
to DB_HOST=localhost
I'm able to run my migrations but them, my container pops up this error:
code: 'ECONNREFUSED',
api | syscall: 'connect',
api | address: '127.0.0.1',
api | port: 3306,
api | fatal: true
Share
Improve this question
edited Jun 14, 2020 at 16:09
CommunityBot
11 silver badge
asked Jun 13, 2020 at 19:20
fjurrfjurr
5522 gold badges10 silver badges23 bronze badges
2
- 1 Did you ever manage to solve this? I keep getting the same exact error message. – Erez Hod Commented Oct 22, 2020 at 10:26
- I'm also getting this error did you manage to solve it @ErezHod? – nick Commented Jun 5, 2022 at 2:57
1 Answer
Reset to default 5Edit
Okay, I just have to separate the port and host into individual fields:
"development": {
"username": "postgres",
"password": "postgres",
"database": "postgres",
"host": "localhost",
"port": "5434",
"dialect": "postgres"
},
I had the same issue with docker-pose
and sequelize-cli
node:
build:
context: ./node
target: dev
volumes:
- ./node/src:/app/src
- ./node/private:/app/private
ports:
- 3111:3000
mand: npm run dev
environment:
- NODE_ENV=development
env_file:
- ./node/.env
depends_on:
- db
db:
image: postgres:12-alpine
ports:
- 5434:5432
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
"development": {
"username": "postgres",
"password": "postgres",
"database": "postgres",
"host": "localhost:5434",
"dialect": "postgres"
}
when i run ❯ npx sequelize-cli db:migrate
I get the following error :
Sequelize CLI [Node: 15.2.1, CLI: 6.2.0, ORM: 6.3.5]
Loaded configuration file "config/config.json".
Using environment "development".
ERROR: getaddrinfo ENOTFOUND localhost:5434
and it works with the following mand, It's more of a workaround
❯ npx sequelize-cli db:migrate --url 'postgres://postgres:postgres@localhost:5434/postgres'
Sequelize CLI [Node: 15.2.1, CLI: 6.2.0, ORM: 6.3.5]
Parsed url postgres://postgres:*****@localhost:5434/postgres
No migrations were executed, database schema was already up to date.
本文标签: javascriptError getaddrinfo ENOTFOUND db when running sequelize migrationsStack Overflow
版权声明:本文标题:javascript - Error getaddrinfo ENOTFOUND db when running sequelize migrations - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742061298a2418602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论