Do you know why I get the following error when I try to run typeorm:run to execute migration?
node --require ts-node/register ./node_modules/typeorm/cli.js migration:run
Error during migration run:
Error: getaddrinfo ENOTFOUND users-service-db
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'users-service-db',
fatal: true
}
error Command failed with exit code 1.
my config is
users-service-db:
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=db
image: mysql:5.7.20
ports:
- "7201:3306"
the users-service-db is running does this Error: getaddrinfo ENOTFOUND users-service-db say that the host doesn't know what to do. Can you help?
After trying Answer 1 and 2 still getting the same error don't know what to do it worked before?
version: "3"
services:
api-gateway:
build:
context: "."
dockerfile: "./api-gateway/Dockerfile"
depends_on:
- chat-service
- users-service
ports:
- "7000:7000"
volumes:
- ./api-gateway:/opt/app
chat-service:
build:
context: "."
dockerfile: "./chat-service/Dockerfile"
depends_on:
- chat-service-db
ports:
- "7100:7100"
volumes:
- ./chat-service:/opt/app
chat-service-db:
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=db
image: mysql:5.7.20
ports:
- "7200:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "7300:80"
volumes:
- ./phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
users-service:
build:
context: "."
dockerfile: "./users-service/Dockerfile"
depends_on:
- users-service-db
ports:
- "7101:7101"
volumes:
- ./users-service:/opt/app
users-service-db:
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=db
image: mysql:5.7.20
ports:
- "7201:3306"
hostname: 'localhost'
finally I resolved the error thanks to @Eranga Heshan
I created an additional ormConfig.js file at pasted this:
export = {
"type": "mysql",
"host": "localhost",
"port": 7201,
"username": "root",
"password": "password",
"database": "db",
"synchronize": true,
"logging": false,
"entities": [
"src/entities/**/*.ts"
],
"migrations": [
"./src/db/migrations/**/*.ts"
],
"cli": {
"entitiesDir": "src/db/entities",
"migrationsDir": "src/db/migrations"
}
}
then
node --require ts-node/register ./node_modules/typeorm/cli.js migration:run --config src/db/migrations/ormConfig
Your VS Code terminal is running inside your machine. So it can't resolve users-service-db host.
You can do this in two ways.
localhostCreate a new typeorm connection config file migrationsOrmConfig.ts and put it inside your project (Let's say you put it in src/migrations directory)
export = {
host: 'localhost',
port: '7201',
type: 'mysql',
user : 'root',
password : 'password',
database : 'db' ,
};
Now you can modify the command you used earlier to run migrations
node --require ts-node/register ./node_modules/typeorm/cli.js migration:run --config src/migrations/migrationsOrmConfig
In your VSCode terminal type
docker ps -a
Get the CONTAINER ID of user-service (Let's say it is CONTAINER_ID)
Open up a terminal inside the container
docker exec -it CONTAINER_ID /bin/bash
Execute the command you used earlier to run migrations (if the following command complained about typeorm node module not being found, you can install it inside the container)
node --require ts-node/register ./node_modules/typeorm/cli.js migration:run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With