Skip to content

Docker deployment of a .NET Core application and SQL Server on Linux using Docker Compose. Made as a school assignment.

Notifications You must be signed in to change notification settings

landervdb/docker-dotnet-core-sql-server-linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ASP.NET Docker image

Author: Lander Van den Bulcke

Disclaimer: This was made as a school assignment. Therefore, no guarantees in terms of quality/functionality. ;)

Docker compose

Preparing application

$ cd app
$ dotnet restore
$ dotnet publish -c Release -o out
$ cd ..

Run entire stack

$ docker-compose up -d

Stop stack

$ docker-compose stop

Stop stack and remove images

$ docker-compose down

Manual

Building the image

$ cd app
$ dotnet restore
$ dotnet publish -c Release -o out
$ cd ..
$ docker build -t landervdb/dotnet-demo .

Create container

$ docker run --name dotnet-demo -p 5000:5000 --link sql-server-demo -e SQLSERVER_HOST=sql-server-demo -d landervdb/dotnet-demo

This command assumes there is already a sql-server container running with the name sql-server-demo (see sql-server folder).

Stop container

$ docker stop dotnet-demo

Start container

$ docker start dotnet-demo

Changes made in application code

  • Program.cs:
var host = new WebHostBuilder()
                .UseUrls("http://*:5000") // Dit toevoegen
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();
  • Startup.cs:
using System;

//...

var hostname = Environment.GetEnvironmentVariable("SQLSERVER_HOST") ?? "localhost";
            var connString = $"Data Source={hostname};Initial Catalog=demoapp;User ID=demouser;Password=DemoPass12;";

            services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connString));
  • General:
$ dotnet migrate

Sources

About

Docker deployment of a .NET Core application and SQL Server on Linux using Docker Compose. Made as a school assignment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages