I’m trying to use entity framework core migrations to create database and table in docker container, but when “dotnet-ef update database” starts executing there is error occurs
Visual Studio generated dockerfile with added migrations commands
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["CurrencyInfoGetter/CurrencyInfoGetter.csproj", "CurrencyInfoGetter/"]
RUN dotnet restore "./CurrencyInfoGetter/CurrencyInfoGetter.csproj"
COPY . .
WORKDIR "/src/CurrencyInfoGetter"
RUN dotnet build "./CurrencyInfoGetter.csproj" -c %BUILD_CONFIGURATION% -o /app/build
FROM build as migrations
ENV PATH="$PATH:/root/.dotnet/tools"
RUN dotnet tool install --global dotnet-ef
RUN dotnet-ef migrations add InitialCreate
RUN dotnet-ef database update
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./CurrencyInfoGetter.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CurrencyInfoGetter.dll"]
Docker-compose.yml
version: '3.4'
volumes:
datafiles:
services:
migrations:
container_name: service-migrations
image: service-migrations
build:
context: .
dockerfile: CurrencyInfoGetter/Dockerfile
target: migrations
depends_on:
- database
database:
image: postgres:16.4
ports:
- "5433:5432"
volumes:
- ~/apps/postgres:/var/lib/postgresql/data
restart: always
environment:
- POSTGRES_PASSWORD=1
- POSTGRES_USER=postgres
- POSTGRES_DB=CurrencyRates
currencyinfogetter:
image: ${DOCKER_REGISTRY-}currencyinfogetter
depends_on:
- database
build:
context: .
dockerfile: CurrencyInfoGetter/Dockerfile
environment:
- ASPNETCORE_URLS=https://+:8081;http://+:8080
- ASPNETCORE_HTTPS_PORT=8081
ports:
- "25565:8080"
- "25566:8081"
Exception code
1>#29 [migrations migrations 3/3] RUN dotnet-ef database update
1>#29 1.748 Build started...
1>#29 4.787 Build succeeded.
1>#29 8.812 System.Net.Sockets.SocketException (00000005, 0xFFFDFFFF): Name or service not known
1>#29 8.813 Name or service not known
Without “dotnet ef database update” error doesn’t appear
New contributor
Dubster is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.