If I understand correctly, you will climb into Docker 2 containers, one with the bank and the other with your API using Nodejs + Express.
You can link them both using Docker-Compose. Here is an example of the Docker-Compose.yml file
version: "3.4"
volumes:
data_sistema:
services:
db_sistema:
image: mysql:5.6
ports:
- "3306:3306"
expose:
- 3306
volumes:
- data_sistema:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=sistema
app_sistema:
build: ./
image: app_sistema
links:
- db_sistema
depends_on:
- db_sistema
environment:
- DB_HOST=db_sistema
- DB_USERNAME=root
- DB_PASSWORD=123456
- DB_DATABASE=sistema
- DB_PORT=3306
- WAIT_HOSTS=db_sistema:3306
ports:
- 3000:3000
Note that in this example I have two services, db_system which is the bank container and app_system which is the API container. In both, I have system variables (section Environment). Note that in app_system, I inform you that db_host is equal to the database service name within this Docker-Compose file.
In your database connection file (database.js) you can make the following change so that the file takes the data from the environment variables:
module.exports = {
dialect: "mysql",
host: process.env.DB_HOST,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
operatorAliases: false,
define: {
timestamps: true,
underscored: true,
underscoredAll: true
}
};
The ideal is to leave this connection information in the file. env from the root of your project, and pull this data from there, rather than leaving it fixed in the connection file.