architecting .net applications for docker and container based deployments

101
Architecting .NET Applications for Docker and Container Based Deployments @Ben_Hall [email protected] Blog.BenHall.me.uk

Upload: ben-hall

Post on 12-Jul-2015

7.071 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Architecting .NET Applications for Docker and Container Based Deployments

Architecting .NET Applications for

Docker and Container Based

Deployments@Ben_Hall

[email protected]

Blog.BenHall.me.uk

Page 2: Architecting .NET Applications for Docker and Container Based Deployments

Who?

Ocelot Uproar

@Ben_Hall

Tech Support > Tester > Developer > Founder >

Freelancer

Page 3: Architecting .NET Applications for Docker and Container Based Deployments

Agenda

• What are containers?

• .NET running inside a Docker Container

• Two Containers

• Three Containers

• Four Containers, More!

• Future of Docker and Windows/.NET

Page 4: Architecting .NET Applications for Docker and Container Based Deployments

A Load Balanced ASP.NET Website

running inside Docker

Page 5: Architecting .NET Applications for Docker and Container Based Deployments

WHAT ARE CONTAINERS?

Page 6: Architecting .NET Applications for Docker and Container Based Deployments

Deployments are hard.

They shouldn’t be.

Page 7: Architecting .NET Applications for Docker and Container Based Deployments

Container

https://www.docker.com/whatisdocker/

Page 8: Architecting .NET Applications for Docker and Container Based Deployments

Container…

Own Process Space

Own Network Interface

Own Root Directories

Sandboxed

Like a lightweight VM. But it’s not a VM.

Page 9: Architecting .NET Applications for Docker and Container Based Deployments

Container…

Native CPU

Native Memory

Native IO

No Pre-Allocation

Zero Performance Overheard

Page 10: Architecting .NET Applications for Docker and Container Based Deployments
Page 11: Architecting .NET Applications for Docker and Container Based Deployments
Page 12: Architecting .NET Applications for Docker and Container Based Deployments

Build, Ship and Run Any App, Anywhere

Docker - An open platform for distributed applications for developers and sysadmins.

Page 13: Architecting .NET Applications for Docker and Container Based Deployments
Page 14: Architecting .NET Applications for Docker and Container Based Deployments

In Real Life?

Digital Ocean Ubuntu Droplet

Node.js Node.js GoLang Mono

Static Site ElasticSearch ElasticSearch

Logstash Kibana Nginx Redis

Page 15: Architecting .NET Applications for Docker and Container Based Deployments

- Easy deployment

- Isolated sandboxes

- Portability

- Development === Production

- Control

Page 16: Architecting .NET Applications for Docker and Container Based Deployments
Page 17: Architecting .NET Applications for Docker and Container Based Deployments

$ boot2docker

https://github.com/boot2docker/windows-installer

Page 18: Architecting .NET Applications for Docker and Container Based Deployments

Production

Page 19: Architecting .NET Applications for Docker and Container Based Deployments
Page 20: Architecting .NET Applications for Docker and Container Based Deployments

Not much .NET on there…

At the moment they’re based on Linux.

Today Mono works, as does XSP and

ASP.NET vNext.

Tomorrow?

Page 21: Architecting .NET Applications for Docker and Container Based Deployments
Page 22: Architecting .NET Applications for Docker and Container Based Deployments
Page 23: Architecting .NET Applications for Docker and Container Based Deployments
Page 24: Architecting .NET Applications for Docker and Container Based Deployments

.NET APPLICATION RUNNING

INSIDE CONTAINER

Page 25: Architecting .NET Applications for Docker and Container Based Deployments

$ docker run

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Page 26: Architecting .NET Applications for Docker and Container Based Deployments

$ docker run--name === Friendly name--rm === Remove when finished-t === Attach to terminal-I === Interactive

Page 27: Architecting .NET Applications for Docker and Container Based Deployments

ASP.NET Example

Page 28: Architecting .NET Applications for Docker and Container Based Deployments

http://blog.benhall.me.uk/2014/10/running-nancyfx-inside-docker-container/

Page 29: Architecting .NET Applications for Docker and Container Based Deployments

Dockerfile

Page 30: Architecting .NET Applications for Docker and Container Based Deployments

Dockerfile - FROM

Page 31: Architecting .NET Applications for Docker and Container Based Deployments
Page 32: Architecting .NET Applications for Docker and Container Based Deployments
Page 33: Architecting .NET Applications for Docker and Container Based Deployments
Page 34: Architecting .NET Applications for Docker and Container Based Deployments

$ docker search

Page 35: Architecting .NET Applications for Docker and Container Based Deployments

Dockerfile – ADD / WORKDIR /

RUN

Page 36: Architecting .NET Applications for Docker and Container Based Deployments

Dockerfile - EXPOSE

Page 37: Architecting .NET Applications for Docker and Container Based Deployments

Dockerfile – CMD /

ENTRYPOINT

Page 38: Architecting .NET Applications for Docker and Container Based Deployments
Page 39: Architecting .NET Applications for Docker and Container Based Deployments

$ docker build--t === Friendly name.

<Docker Hub Username>/<ProjectName>

Page 40: Architecting .NET Applications for Docker and Container Based Deployments

$ docker images

Page 41: Architecting .NET Applications for Docker and Container Based Deployments
Page 42: Architecting .NET Applications for Docker and Container Based Deployments
Page 43: Architecting .NET Applications for Docker and Container Based Deployments

$ docker run

Page 44: Architecting .NET Applications for Docker and Container Based Deployments

$ docker ps-a === Show all containers

Page 45: Architecting .NET Applications for Docker and Container Based Deployments

$ docker logs-f === tail the logs – watch them in real time

Page 46: Architecting .NET Applications for Docker and Container Based Deployments

$ docker run –p $CONTAINERPORT

Page 47: Architecting .NET Applications for Docker and Container Based Deployments

Why “$ curl 0.0.0.0:49218” ?

Page 48: Architecting .NET Applications for Docker and Container Based Deployments

$ boot2docker ip

Page 49: Architecting .NET Applications for Docker and Container Based Deployments

$ curl b2d:49218

Page 50: Architecting .NET Applications for Docker and Container Based Deployments
Page 51: Architecting .NET Applications for Docker and Container Based Deployments

Environment Variables

Page 52: Architecting .NET Applications for Docker and Container Based Deployments

$ docker push

Page 53: Architecting .NET Applications for Docker and Container Based Deployments
Page 54: Architecting .NET Applications for Docker and Container Based Deployments
Page 55: Architecting .NET Applications for Docker and Container Based Deployments

$ docker export / save

Page 56: Architecting .NET Applications for Docker and Container Based Deployments

$ docker import / load

Page 57: Architecting .NET Applications for Docker and Container Based Deployments

What do we have?

$ cd ~/SourceControl/HelloWorldVNext

$ cat Dockerfile

$ docker build -t benhall/aspnetvnext .

$ docker run -d -t -i -p 5000:5000 benhall/aspnetvnext

$ curl 192.168.59.103:5000

<h1>Hello from Razor!!<h1>

<h2>From 95a28c090686</h2>

$ docker push benhall/aspnetvnext

Page 58: Architecting .NET Applications for Docker and Container Based Deployments

TWO CONTAINERS

Page 59: Architecting .NET Applications for Docker and Container Based Deployments

Storing Data - Volumes

-v /opt/docker/scrapbook_elasticsearch:/data

-v /opt/docker/mysql:/var/lib/mysql

-v /docker/scrapbook/uploads:/app/public/uploads

Page 60: Architecting .NET Applications for Docker and Container Based Deployments
Page 61: Architecting .NET Applications for Docker and Container Based Deployments

$ docker run –link CONTAINER:ALIAS

Page 62: Architecting .NET Applications for Docker and Container Based Deployments
Page 63: Architecting .NET Applications for Docker and Container Based Deployments

Two Websites On Port 80?

Page 64: Architecting .NET Applications for Docker and Container Based Deployments

Nginx

Page 65: Architecting .NET Applications for Docker and Container Based Deployments
Page 66: Architecting .NET Applications for Docker and Container Based Deployments
Page 67: Architecting .NET Applications for Docker and Container Based Deployments
Page 68: Architecting .NET Applications for Docker and Container Based Deployments

DockerGenGenerate files from docker container meta-data

https://github.com/jwilder/docker-gen

Page 69: Architecting .NET Applications for Docker and Container Based Deployments
Page 70: Architecting .NET Applications for Docker and Container Based Deployments
Page 71: Architecting .NET Applications for Docker and Container Based Deployments
Page 72: Architecting .NET Applications for Docker and Container Based Deployments

https://github.com/jwilder/nginx-proxy

Page 73: Architecting .NET Applications for Docker and Container Based Deployments

THREE CONTAINERS

Page 74: Architecting .NET Applications for Docker and Container Based Deployments

Fig

Page 75: Architecting .NET Applications for Docker and Container Based Deployments
Page 76: Architecting .NET Applications for Docker and Container Based Deployments

$ fig up

Page 77: Architecting .NET Applications for Docker and Container Based Deployments

Identical for Mono/ASP.NET

Page 78: Architecting .NET Applications for Docker and Container Based Deployments

FOUR AND MORE!

Page 79: Architecting .NET Applications for Docker and Container Based Deployments
Page 80: Architecting .NET Applications for Docker and Container Based Deployments

http://www.ryantomlinson.com/consul-service-discovery-in-a-microservice-world/

Page 81: Architecting .NET Applications for Docker and Container Based Deployments

1) Like DockerGen, Consul

raises events on docker

events

2) Registrator adds new

containers details into Consul

3) Consul links containers IP /

Ports to DNS names

Page 82: Architecting .NET Applications for Docker and Container Based Deployments

[tag.]<service>.service[.datacenter][.domain]

$ ping redis.service.east-aws.consul

$ ping redis.service.consul

Page 83: Architecting .NET Applications for Docker and Container Based Deployments
Page 84: Architecting .NET Applications for Docker and Container Based Deployments

https://github.com/BenHall/docker-loadbalancer-aspnet-demo

Page 85: Architecting .NET Applications for Docker and Container Based Deployments

BRING IT BACK TO .NET

Page 86: Architecting .NET Applications for Docker and Container Based Deployments

How should the app be

structure?

Page 87: Architecting .NET Applications for Docker and Container Based Deployments

DOCKER AND AZURE

Page 88: Architecting .NET Applications for Docker and Container Based Deployments

$ azure vm docker create -e 22 -l 'West US' ubuntu-docker

"b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-

amd64-server-20140618.1-en-us-30GB" rgardler 1234abcdE$

http://msopentech.com/blog/2014/09/11/docker_host_in_azure/

Page 89: Architecting .NET Applications for Docker and Container Based Deployments

$ docker --tls

-H tcp://ubuntu-docker.cloudapp.net:4243

info

http://msopentech.com/blog/2014/08/15/getting_started_docker_on_microsoft_azure/

Page 90: Architecting .NET Applications for Docker and Container Based Deployments

$ docker --tls

-H tcp://ubuntu-docker.cloudapp.net:4243

run -t -i ubuntu bash

http://msopentech.com/blog/2014/08/15/getting_started_docker_on_microsoft_azure/

Page 91: Architecting .NET Applications for Docker and Container Based Deployments
Page 92: Architecting .NET Applications for Docker and Container Based Deployments

THE FUTURE?

Page 93: Architecting .NET Applications for Docker and Container Based Deployments

Docker and Microsoft

Partnership

Page 94: Architecting .NET Applications for Docker and Container Based Deployments

SQL Server as a Container?

Page 95: Architecting .NET Applications for Docker and Container Based Deployments
Page 96: Architecting .NET Applications for Docker and Container Based Deployments

Visual Studio as a Container?

Page 97: Architecting .NET Applications for Docker and Container Based Deployments
Page 98: Architecting .NET Applications for Docker and Container Based Deployments

IN SUMMARY…

Page 99: Architecting .NET Applications for Docker and Container Based Deployments

Only tool I use for deployment

• Close gap between development and production

• Everything is a container!

• Running platforms like Logstash, ElasticSearch, Redis, EventStore, RavenDB, NancyFX etc? Consider containers for deployment.

Page 100: Architecting .NET Applications for Docker and Container Based Deployments
Page 101: Architecting .NET Applications for Docker and Container Based Deployments

THANK YOU

@[email protected]