Deploying SQL Server database with dbup on Docker

0

At our company we use a couple methods of updating database models. we use sqlproj and dacpacs as well as we have a .net core app using DbUp. I have successfully containerized using dacpac based of this article automating-sql-server-2019-docker-deployments

Now I am working on Db Up. There are a few challenges that I've tried to sort out but I am not able to sort through them.

  1. My first though was to gen a dockerfile based off mcr.microsoft.com/mssql/server:2019-latest then install the .net core runtime and run the built dbup inside sql container. It has been hard to get the .net core runtime running I just can't seem to get it to work.

  2. I was trying to use docker-compose to buildjust a norm sql db and also run the dbUp using a base image mcr.microsoft.com/dotnet/core/sdk:3.1 AS build and connect to the sql db this way. this is also not working here is my docker-compose.yml file(sorry for some reason i can't coy the code correctly here:

version: "3.7" services: ms-sql-server:
image: mcr.microsoft.com/mssql/server:2019-latest ports: - "1477:1433" environment: SA_PASSWORD: "SuperFun!23" ACCEPT_EULA: "Y" dbup-exe: build: .
depends_on: - ms-sql-server

enter image description here

In my Dockerfile I am calling the db but it won't connect to it

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["/Sentinel.DbUp.csproj", "Sentinel.DbUp/"]
RUN dotnet restore "Sentinel.DbUp/Sentinel.DbUp.csproj"
WORKDIR "/src/Sentinel.DbUp"
COPY . .
RUN dotnet build "Sentinel.DbUp.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Sentinel.DbUp.csproj" -c Release -o /app
RUN dotnet run Sentinel.DbUp --ConnectionString=Server=ms-sql-server,1477;Database=Sentinel_Local;User Id=sa;Password=SuperFun!23; --WithSeedOnce --EnsureDatabase --PerformUpgrade

I have two errors

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible

/bin/sh: 1: User: not found /bin/sh: 1: --WithSeedOnce: not found

Based on my research, I though when using docker compose between docker images you can reference ms-sql-server instead of local host. also when executing the last command how do I append multiple arguments? it seems --WithSeedOnce is not considered and argument for the app

sql-server
linux
docker
docker-compose
dbup
asked on Stack Overflow Feb 3, 2021 by greektreat • edited Feb 3, 2021 by Dale K

1 Answer

0

So, from what I gather, there are two things that jump off the page:

  • In a dockerfile, RUN instructions are executed when the image is built. Entrypoint or command instructions are executed when the container is started. As such, the command to start the DbUp (which I assume is the last line in your current dockerfile) should be changed from RUN to entrypoint.

  • using the depends on instruction does not mean that the docker will wait for your database to be ready before starting the DbUp container. It just means that the database container will be launch before your DbUp is launched. Instead you have to wait for the DB in you code or using a wrapper script like wait-for-it. Check the documentation here

answered on Stack Overflow Feb 3, 2021 by camba1

User contributions licensed under CC BY-SA 3.0