Repository navigation
Closed
Labels
Milestone
Description
Describe the bug
I have followed some articles to be able to use the aspnet core application with sql server.
Unfortunately the migration command does not run.
Steps to reproduce the issue
Provide steps for us to reproduce the issue
- Creating a new Asp.net Core 2.2 Web (MVC) project from the official template in the Visual Studio 2019.
- Adding Docker-Compose support to the project.
version: '3.4'
services:
api:
image: ${DOCKER_REGISTRY-}api
build:
context: .
dockerfile: Api/Dockerfile
depends_on:
- db
db:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "Your_password123"
ACCEPT_EULA: "Y"
The Docker file was generated by Visual Studio. I inserted some line to run the entrypoint.sh
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["Api/Api.csproj", "Api/"]
RUN dotnet restore "Api/Api.csproj"
COPY . .
WORKDIR "/src/Api"
RUN dotnet build "Api.csproj" -c Release -o /app
FROM build AS publish
# Inserted lines
COPY ./entrypoint.sh ./app/
RUN chmod +x ./app/entrypoint.sh
CMD /bin/bash ./app/entrypoint.sh
RUN dotnet publish "Api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Api.dll"]
Entrypoint.sh is from the tutorial of docker page.
#!/bin/bash
set -e
run_cmd="dotnet run --server.urls http://*:80"
until dotnet ef database update; do
>&2 echo "SQL Server is starting up"
sleep 1
done
>&2 echo "SQL Server is up - executing command"
exec $run_cmd
Expected behavior
When I run the Docker-Compose project in VS 2019 then I expect the migration has run. But this is not happen.
Additional information
I did not find any official step-by-step tutorial.
Reacted by Donatas Bražionis, Roman Himadinov, David Senecal, Simon Eddeland, Jean Francisco Flores Gatto, davelowndes, falcevor, alenavor and Naxilos
Activity
natemcmaster commentedon May 29, 2019
Migrations do not automatically run when your application begins. Running
dotnet App.dllwill only start the web server. A separate action is required to run migrations.@ajcvickers - do you have documentation or recommendations on how to achieve migrations inside a docker workflow?
[-]SQL Migration does not run.[/-][+]SQL Migration does not run in docker[/+]alexk8 commentedon May 31, 2019
short answer might be
But I wouldn't say that it's recommended
ajcvickers commentedon Jun 3, 2019
Notes from triage:
ajcvickers commentedon Sep 17, 2020
Assigning to @bricelam to review; may be not action here.
syedhassaanahmed commentedon Nov 17, 2020
@ajcvickers Any updated guidance on how to run migrations in Docker?
ajcvickers commentedon Nov 19, 2020
@syedhassaanahmed No; this issue is tracking adding this guidance to the docs.
davelowndes commentedon Feb 15, 2021
I have resolved via option 3:
docker-compose.ymlIDesignTimeDbContextFactorycdto the project with theDbContextand provide the connection string via new--connectionparameter (EF Core 5.0)My run-time connection is set up using normal appsettings.json:
CyberoxiDevops commentedon Mar 10, 2022
Hi, any updates ?
ddatdt12 commentedon Sep 3, 2022
I have the same problem. Any solution for that ?
lolalilox commentedon Apr 29, 2024
I have the same problem. Any solution for that ?
lolalilox commentedon Apr 29, 2024
So I just resorted back into doing Update-Database manually after doing a docker compose, I guess this could somewhat be automated with a script of some kind. Thanks either way though.
Expand and clarify migrations guidance. (dotnet#5445)