![]() ![]() Original Comments Feedback Bot on, 04:25 AM: b_0()Īt .MigrationsDomainCommand.Execute(Action command) System.ArgumentNullException: Value cannot be null.Īt (Type type, BindingFlags bindingAttr, Binder binder, Object args, CultureInfo culture, Object activationAttributes)Īt (Type type, Object args)Īt .(Project project, Int32 shellVersion)Īt .(Project project)Īt .(Project project)Īt .MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)Īt .UpdateDatabaseCommand.c_Displa圜lass2. FullyQualifiedErrorId : FileNotFoundException.CategoryInfo : NotSpecified: (:), MethodInvocationException.You should see the Products table with the same products returned from the Web API above. You will be able to connect to the database available in the SQL Server running in the Docker container. Provide the password myStong_Password123# for the default user sa that we configured in the docker-compose.yml file above. Open SSMS and type the localhost,8002 in the Server name field. This means we can remotely connect SQL Server running inside the Docker container using the SSMS installed on the host machine. If you remember, we mapped the default SQL Server port 1433 with port 8002 in the docker-compose.yml file above. Connect SQL Server Docker Container using SSMS If you will try to access your Web API in the browser, you will see an output similar to the following screenshot where the product data is returned from the database. Press F5 in Visual Studio and wait for some time and finally, you will be able to see both containers appearing in the Docker Desktop. It is now time to build and run our containers using the configurations available in the docker-compose.yml file. Running Web API and SQL Server Containers using Docker Compose "DefaultConnection": "Server=SqlServerDb Database=OnlineShopDb User Id=sa Password=myStong_Password123# Trust Server Certificate=True " Next, we need to define our database connection string and we can save the connection string in the appsettings.json file as shown below: appsettings.json Basically, we are creating a database and a Products table and we want to add some initial data in that Products table that’s why we are overriding the OnModelCreating method of DbContext in the above code which allows us to seed data. We are using EF Core Code First approach and if you are not familiar with this then I will recommend you to read my post Data Access in ASP.NET Core using EF Core (Code First). Protected override void OnModelCreating(ModelBuilder modelBuilder) Var dbCreater = Database.GetService() as RelationalDatabaseCreator Public OnlineShopDbContext(DbContextOptions options) Public class OnlineShopDbContext : DbContext Open the NuGet package manager and search and install the following packages in your project. The first thing we need is to install Entity Framework Core and SQL Server Data Provider. RUN dotnet publish "WebApiSqlServerDockerDemo.csproj" -c Release -o /app/publish /p:UseAppHost=falseĮNTRYPOINT RUN dotnet build "WebApiSqlServerDockerDemo.csproj" -c Release -o /app/build ![]() RUN dotnet restore "WebApiSqlServerDockerDemo/WebApiSqlServerDockerDemo.csproj" #See to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.įROM /dotnet/aspnet:7.0 AS baseįROM /dotnet/sdk:7.0 AS buildĬOPY NET 7.0 and make sure you enable the Docker support while you are creating the project. Let’s create a new ASP.NET Core Web API project WebApiSqlServerDockerDemo in Visual Studio 2022 using. Stream the log output of running servicesĬreating ASP.NET Core Web API with Docker Support.Docker Compose greatly streamlines collaboration among teams and ensures consistent deployment across various environments, making it an indispensable tool for containerized application development. This file acts as a blueprint for managing the whole lifecycle of your application and allows you to configure multiple interconnected services and their settings. It enables developers to define and configure all the services, networks, and volumes required for an application in a single YAML file. Some experience with ASP.NET Core Web API and EF Coreĭocker Compose is a powerful tool used to simplify the management and deployment of multi-container applications. ![]() To follow along with this tutorial, you need to have:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |