I develop a WebAPI service in dotnet core 2.2. I use Docker desktop for windows with Linux containers I have this docker-compose file
version: '3.4'
services:
mongo:
image: mongo
ports:
- 27017:27017
mongo-express:
image: mongo-express
ports:
- 8088:8081
depends_on:
- mongo
MyWebApi:
image: MyWebApi
build:
context: .
dockerfile: MyWebApi/Dockerfile
ports:
- 80:80
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://+:5003
depends_on:
- mongo
and this Dockerfile for my web api :
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
#EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["TMSApi/TMSApi.csproj", "TMSApi/"]
COPY ["BusinessEntities/BusinessEntities.csproj", "BusinessEntities/"]
COPY ["TMSService/TMSService.csproj", "TMSService/"]
COPY ["TMSRepository/TMSRepository.csproj", "TMSRepository/"]
RUN dotnet restore "TMSApi/TMSApi.csproj"
COPY . .
WORKDIR "/src/TMSApi"
RUN dotnet build "TMSApi.csproj" -c Debug -o /app
FROM build AS publish
RUN dotnet publish "TMSApi.csproj" -c Debug -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TMSApi.dll", "--environment=Development"]
In my webapi appsettings.json, i use this connection string :
mongodb://mongo:27017
In the docker-compose file i have 3 services : mongo, mongo-express and MyWebApi mongo-express is connected to mongo when i use localhost:8088.
But i have a timeout when MyWebApi try to connect to mongo service.
Do you have an idea how to fix this ? i want to keep this running inside docker containers
I found some recent articles on the subject but with no result...
Thanks