Thonk
Thonk
CC#
Created by Thonk on 12/7/2024 in #help
Docker and .NET migrations
Hello everyone, I created a Dockerfile for each of my APIs (using .NET 9) and a Docker Compose file to containerize all my applications. I've done some research, but I have a few questions: In a microservices architecture, should each service have its own database? (e.g., Auth.API => PostgreSQL and Story.API => MongoDB) Also, I can't apply the EF migrations once my Auth service is running in its container. I checked this link: https://www.reddit.com/r/csharp/comments/1h3kt2r/aspnet_8_and_docker/ I understand the theory of adding a separate Dockerfile just to apply the migration once the API and the database are up and running in the container, but I can't figure out how to implement it. Do you have any advice or ideas?
services:
auth-db:
container_name: AuthDB
image: postgres:17-alpine
environment:
ASPNETCORE_ENVIRONMENT: Development
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
networks:
- verset-network

auth-api:
container_name: AuthAPI
build:
context: ./Services/Auth.API
dockerfile: Dockerfile
environment:
ASPNETCORE_ENVIRONMENT: Development
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
depends_on:
- auth-db
networks:
- verset-network

tales-db:
image: mongo:7.0
container_name: TalesDB
environment:
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}

story-api:
container_name: StoryAPI
build:
context: ./Services/Story.API
dockerfile: Dockerfile
depends_on:
- tales-db
networks:
- verset-network

volumes:
storydb-data:
driver: local

networks:
verset-network:
driver: bridge
services:
auth-db:
container_name: AuthDB
image: postgres:17-alpine
environment:
ASPNETCORE_ENVIRONMENT: Development
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
networks:
- verset-network

auth-api:
container_name: AuthAPI
build:
context: ./Services/Auth.API
dockerfile: Dockerfile
environment:
ASPNETCORE_ENVIRONMENT: Development
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
depends_on:
- auth-db
networks:
- verset-network

tales-db:
image: mongo:7.0
container_name: TalesDB
environment:
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}

story-api:
container_name: StoryAPI
build:
context: ./Services/Story.API
dockerfile: Dockerfile
depends_on:
- tales-db
networks:
- verset-network

volumes:
storydb-data:
driver: local

networks:
verset-network:
driver: bridge
Thanks in advance for your help!
6 replies
CC#
Created by Thonk on 11/29/2024 in #help
Looking for a mentor
Hello everyone! I'm an ASP.NET Core developer with 2 years of experience, currently working on a mini social network project. Right now, I'm focusing solely on the back end. My goal is to build separate APIs and databases for each feature (e.g., Publication.API, User.API, Auth.API) and connect them through an API Gateway. I'm looking for someone more experienced who has some time to guide me, answer questions, and help me grow as a developer—a mentor, essentially. If you're interested and available, I’d really appreciate your help!
4 replies