Alex Thissen Shifting Gears For .NET Developers
Alex Thissen Shifting Gears For .NET Developers
Containers
• Docker
• Visual Studio 2017 tooling
• Docker-
compose Composition
• Environments
• Orchestrators
Clusters • Containerized
application lifecycle
• Summary
• Questions and Wrap up
answers
Inner loop
Validate Run
Code
Outer loop
Demo #1
Diving straight into
Docker containers
Container technology
Docker 101
Container
management
Docker
Engine
Compute
Client applications (browser) ASP.NET Core
Web App
Web
Page
HTML 5
JavaScript
game container container
Leaderboard Identity
Microservice Microservice
Demo #2
Highscore application
Docker containers and
Visual Studio 2017
Your application layer:
e.g. dotnext/gamingwebapp:latest
microsoft/aspnetcore:1.1.1
microsoft/dotnet:1.0.0-sdk
microsoft/dotnet:1.1.1-runtime
microsoft/dotnet:1.1.1-runtime-deps
microsoft/nanoserver:10.0.14393.1066
-or- debian/jessie
Sources
In C# this would be
source ?? “obj/Docker/Publish”
Determined by VS2017 in
DOCKER_BUILD_SOURCE
Demo #3
Running
containers
in VS2017
Sources
Debugger
~
%USER_PROFILE%
Demo #4
Debugging
containers
in VS2017
Composing applications
from containers
Orchestration tool for container automation
Web App
Web API
container
Leaderboard
Microservice
VS2017 currently uses 2.1
services Support for 3.x coming soon
service-name
docker-image
how to build image
networks
other services network-name
services:
ci-build:
image: microsoft/aspnetcore-build:1.0-1.1
volumes:
- .:/src
working_dir: /src
command: /bin/bash -c "dotnet restore ./DotNextGaming.sln
&& dotnet publish ./DotNextGaming.sln -c Release -o ./obj/Docker/publish"
Demo #5
Building compositions
docker-compose
-f "docker-compose.yml"
-f "docker-compose.override.yml“
-p composition up -d
Demo #6
Working with
compositions
{
"ConnectionString": "Server=tcp:…",
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:1337
- ConnectionString=Server=sql.data;…
environment: {
- ASPNETCORE_ENVIRONMENT=Production "ConnectionString": "Server=tcp:…",
- ASPNETCORE_URLS=http://0.0.0.0:80 "Logging": {
- ConnectionString=DOCKERSECRETS_KEY "IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
// Key/value collection with indexer
Configuration["LeaderboardBaseUrl"];
Configuration["ConnectionStrings:LeaderboardContext"];
// Or special extension methods
Configuration.GetConnectionString("LeaderboardContext");
// appsettings.json
{
"LeaderboardBaseUrl": "http://localhost:1337/api",
"ConnectionStrings": {
"LeaderboardContext": "Server=tcp:127.0.0.1,3433; …"
}, …
}
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.Configure<WebAppSettings>(Configuration);
services.AddMvc();
} public class WebAppSettings {
public string Setting1 …
public int Setting2 …
public class HomeController : Controller }
{
private readonly IOptionsSnapshot<WebAppSettings> settings;
Validate Run
Code
Outer loop
Demo #7
Deploying and hosting in a
Docker Swarm cluster
Demo #8
Visual Studio Team Services
Build and release pipelines
Inner loop
Validate Run
Code
Outer loop
Resources
http://dot.net
http://docs.docker.com
http://hub.docker.com/microsoft/
http://visualstudio.com
https://docs.microsoft.com/en-us/