Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Architecting .NET Applications for Docker and Container Based Deployments

13,624 views

Published on

Presented at NDC London, 4th December 2014

Published in: Technology
  • Nice summary Ben. For those interested in Docker on Windows, WinDocks has released a port of the Docker engine for Widows 8, 10, Windows Server 2012 and 2016, with full support of SQL Server 2008 through 2016. A free Community Edition is available at WinDocks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Architecting .NET Applications for Docker and Container Based Deployments

  1. 1. Architecting .NET Applications for Docker and Container Based Deployments @Ben_Hall Ben@BenHall.me.uk Blog.BenHall.me.uk
  2. 2. Who? @Ben_Hall Tech Support > Tester > Developer > Founder > Freelancer Ocelot Uproar
  3. 3. Agenda • What are containers? • .NET running inside a Docker Container • Two Containers • Three Containers • Four Containers, More! • Future of Docker and Windows/.NET
  4. 4. A Load Balanced ASP.NET Website running inside Docker
  5. 5. WHAT ARE CONTAINERS?
  6. 6. Deployments are hard. They shouldn’t be.
  7. 7. Container https://www.docker.com/whatisdocker/
  8. 8. Container… Own Process Space Own Network Interface Own Root Directories Sandboxed Like a lightweight VM. But it’s not a VM.
  9. 9. Container… Native CPU Native Memory Native IO No Pre-Allocation Zero Performance Overheard
  10. 10. Build, Ship and Run Any App, Anywhere Docker - An open platform for distributed applications for developers and sysadmins.
  11. 11. In Real Life? Digital Ocean Ubuntu Droplet Node.js Node.js GoLang Mono Static Site ElasticSearch ElasticSearch Logstash Kibana Nginx Redis
  12. 12. - Easy deployment - Isolated sandboxes - Portability - Development === Production - Control
  13. 13. $ boot2docker https://github.com/boot2docker/windows-installer
  14. 14. Production
  15. 15. Not much .NET on there… At the moment they’re based on Linux. Today Mono works, as does XSP and ASP.NET vNext. Tomorrow?
  16. 16. .NET APPLICATION RUNNING INSIDE CONTAINER
  17. 17. $ docker run Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
  18. 18. $ docker run --name === Friendly name --rm === Remove when finished -t === Attach to terminal -I === Interactive
  19. 19. ASP.NET Example
  20. 20. http://blog.benhall.me.uk/2014/10/running-nancyfx-inside-docker-container/
  21. 21. Dockerfile
  22. 22. Dockerfile - FROM
  23. 23. $ docker search
  24. 24. Dockerfile – ADD / WORKDIR / RUN
  25. 25. Dockerfile - EXPOSE
  26. 26. Dockerfile – CMD / ENTRYPOINT
  27. 27. $ docker build --t === Friendly name. <Docker Hub Username>/<ProjectName>
  28. 28. $ docker images
  29. 29. $ docker run
  30. 30. $ docker ps -a === Show all containers
  31. 31. $ docker logs -f === tail the logs – watch them in real time
  32. 32. $ docker run –p $CONTAINERPORT
  33. 33. Why “$ curl 0.0.0.0:49218” ?
  34. 34. $ boot2docker ip
  35. 35. $ curl b2d:49218
  36. 36. Environment Variables
  37. 37. $ docker push
  38. 38. $ docker export / save
  39. 39. $ docker import / load
  40. 40. 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
  41. 41. TWO CONTAINERS
  42. 42. Storing Data - Volumes -v /opt/docker/scrapbook_elasticsearch:/data -v /opt/docker/mysql:/var/lib/mysql -v /docker/scrapbook/uploads:/app/public/uploads
  43. 43. $ docker run –link CONTAINER:ALIAS
  44. 44. Two Websites On Port 80?
  45. 45. Nginx
  46. 46. DockerGen Generate files from docker container meta-data https://github.com/jwilder/docker-gen
  47. 47. https://github.com/jwilder/nginx-proxy
  48. 48. THREE CONTAINERS
  49. 49. Fig
  50. 50. $ fig up
  51. 51. Identical for Mono/ASP.NET
  52. 52. FOUR AND MORE!
  53. 53. http://www.ryantomlinson.com/consul-service-discovery-in-a-microservice-world/
  54. 54. 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
  55. 55. $ ping redis.service.east-aws.consul $ ping redis.service.consul [tag.]<service>.service[.datacenter][.domain]
  56. 56. https://github.com/BenHall/docker-loadbalancer-aspnet-demo
  57. 57. BRING IT BACK TO .NET
  58. 58. How should the app be structure?
  59. 59. DOCKER AND AZURE
  60. 60. $ 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/
  61. 61. $ docker --tls -H tcp://ubuntu-docker.cloudapp.net:4243 info http://msopentech.com/blog/2014/08/15/getting_started_docker_on_microsoft_azure/
  62. 62. $ 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/
  63. 63. THE FUTURE?
  64. 64. Docker and Microsoft Partnership
  65. 65. SQL Server as a Container?
  66. 66. Visual Studio as a Container?
  67. 67. IN SUMMARY…
  68. 68. 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.
  69. 69. THANK YOU @Ben_Hall Ben@BenHall.me.uk Blog.BenHall.me.uk

×