-1
Hello!
I have my development environment set up in Docker.
package json.:
{
"name": "teste_sequelize",
"version": "1.0.0",
"description": "teste do sequelize",
"main": "app.js",
"scripts": {
"start": "clear && nodemon app.js"
},
"author": "eu",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"consign": "^0.1.6",
"ejs": "^3.0.1",
"express": "^4.17.1",
"express-validator": "^5.3.1",
"moment": "^2.24.0",
"mysql2": "^2.1.0",
"sequelize": "^5.21.3"
},
"devDependencies": {
"jest": "^24.9.0",
"nodemon": "^1.19.2",
"sequelize-cli": "^5.5.1"
}
}
Dokerfile:
FROM node:alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 1234
CMD [ "npm","start" ]
Docker-Compose.yml:
version: "3"
volumes:
data:
services:
db:
image: mysql:5.6
ports:
- "3306:3306"
volumes:
- data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=rafaesah
- MYSQL_DATABASE=my_db
- TZ=America/Bahia
myadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- 80:80
environment:
- PMA_ARBITRARY=1
app:
build: .
command: npm start
depends_on:
- db
ports:
- "1234:1234"
expose:
- "1234"
links:
- db
- myadmin
volumes:
- .:/usr/app
config;database.js:
module.exports = {
username: 'root',
password: 'senha',
database: 'my_db',
host: 'db',
port: '3306',
dialect: 'mysql',
};
When I run npm start in the terminal, and access routes via express the connection is successful. But open another terminal and try npx sequelize db:migrate he accuses erro: getaddrinfo ENOTFOUND. If I change the host in config/database.js for localhost to migrate works.
How to configure to work migrate without having to change the host every time?
Can you verify the answer? Don’t forget to accept it if you are satisfied with it.
– tvdias