TLDR: NestJs server with PostgreSQL database and sequelize-typescript ORM working in development (started locally via npm and postgres database running on mac) but not when builded and deployed containerized with docker-compose.
I've pinned the problem down up to this point in my database.provider.ts
where the connection to the database via sequelize-typescript is made:
export const databaseProviders = [
{
provide: 'SEQUELIZE',
useFactory: async (configService: ConfigService) => {
const sequelize = new Sequelize(configService.sequelizeOrmConfig);
sequelize.addModels([
Model1,
Model2,
Model3,
]);
await sequelize.sync();
return sequelize;
},
inject: [ConfigService],
},];
The application container is starting up to this point: await sequelize.sync();
From there the app does not start further, so i guess something is blocking the connection to the database. When i comment this part out, the app is starting (but of course without database-connection). When i run it locally in development it works too.
Maybe my docker-compose.yml is relevant too:
version: '3.5'
services:
testname_app:
container_name: testname_app
image: registry.acme.com/test/test
env_file:
- .env
depends_on:
- postgres
links:
- postgres:postgres
networks:
- testname-network
restart: unless-stopped
postgres:
container_name: postgres
image: postgres
env_file: .env
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- testname-network
restart: unless-stopped
networks:
testname-network:
driver: bridge
volumes:
pgdata:
Solved this by switching from FROM node:latest
to FROM node:lts
in my Dockerfile. Memo to myself: Never pulling from latest again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.