0
I have an application running back end with Nestjs, Typeorm and Mongodb and my front end running React.
I created a Docker container to run all applications but I have a problem.
To run my local back end the connection url is mongodb://localhost:27017/db and for the Docker I need to use mongodb://Mongo:27017/db
Is there any way I can configure my Docker-Composer.yml to make this change?
Below my Docker Compose.
version: "3.7"
services:
client:
build:
context: ./web
dockerfile: Dockerfile
restart: always
ports:
- "3000:3000"
working_dir: /web/src/app
volumes:
- ./web:/web/src/app
entrypoint: ["npm", "start"]
links:
- api
networks:
- webappnetwork
api:
build:
context: ./backend
dockerfile: Dockerfile
restart: always
ports:
- "3333:3333"
volumes:
- ./backend:/backend
- /backend/node_modules
depends_on:
- mongodb
networks:
- webappnetwork
mongodb:
image: mongo
restart: always
container_name: mongodb
volumes:
- ./data:/data/db
ports:
- 27018:27017
command: mongod --noauth
networks:
- webappnetwork
networks:
webappnetwork:
driver: bridge
Below my bd connection file.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CardsModule } from './cards/cards.module';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [
CardsModule,
TypeOrmModule.forRoot({
type: 'mongodb',
url: 'mongodb://localhost:27017/db',
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
useUnifiedTopology: true,
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Thank you all!