Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Dockerising ASP.NET Core Applications

Dockerising ASP.NET Core Applications

An introduction to developing ASP.NET Core apps with Docker. Also covers multi-container deployment with Docker Compose.

Avatar for Anthony Sneed

Anthony Sneed

April 21, 2016
Tweet

More Decks by Anthony Sneed

Other Decks in Technology

Transcript

  1. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Dockerising ASP.NET Core Applications Anthony Sneed Twitter: @tonysneed Email: [email protected]
  2. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    About Me • Status: Married, three children • Locations: Los Angeles, Dallas, Slovakia • Blog: blog.tonysneed.com • Open Source Frameworks: Trackable Entities, Simple MVVM Toolkit Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek wintellect.com kliant.com globalknowledge.com
  3. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Get the Bits github.com / tonysneed / DevWeek.2016.AspNetCore-Docker
  4. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Agenda • ASP.NET Core overview • Introduction to Docker • Docker toolbox, basic commands • Defining Docker images with a Dockerfile • Hooking containers to source code • Linking containers with Docker Compose
  5. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    What is ASP.NET Core*? • Open-source, cross-platform • Modular, cloud-friendly • Highly performant, lightweight * Formerly named ASP.NET 5
  6. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    ASP.NET Core: Why Should I Care? • No longer shackled to one tool chain • Easily mix and match web frameworks • Enables cloud-first development
  7. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    What is Docker? • Isolated like a virtual machine • But more lightweight • Easily deploy and scale microservices
  8. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker: Why Should I Care? • Containers isolated from dev machine • Dev environment matches production • Link containers together with
 docker compose
  9. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker Concepts • Images • Read-only: environment + app • Layered on top of other images • Containers • Read-write: instance of an image • Isolated from other containers
  10. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Getting Started with Docker • Go to docker.com and click Get Started • Install the Docker Toolbox • Oracle Virtual Box • CLI and GUI clients • docker-machine • docker-compose
  11. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker Machine Commands docker-machine ls docker-machine start [machine name] docker-machine stop [machine name] docker-machine env [machine name] docker-machine ip [machine name]
  12. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker Image Commands docker pull [image name] docker build [current dir] docker images docker rmi [image ID]
  13. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker Container Commands docker run [image name] docker ps -a [list containers] docker inspect [container id / name] docker rm [container id / name]
  14. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Dockerfile: Image Definition Dockerfile Docker Image Build
  15. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Dockerfile: Sample Commands FROM [base image]
 MAINTAINER [author]
 COPY, WORKDIR
 RUN [command, args]
 EXPOSE [port]
 ENTRYPOINT [command, args]
  16. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Sample Dockerfile: ASP.NET Core FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr MAINTAINER Anthony Sneed COPY . /app WORKDIR /app RUN ["dnu", "restore"] ENV "ASPNET_ENV=Staging" EXPOSE 5000 ENTRYPOINT ["dnx", "web"]
  17. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Start Containers: Docker run command docker run -d -p 5000:5000 --name web1 [image name] Optional
 Container Name Image
 Name Port
 Mapping Run in
 Deamon Mode
  18. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Volumes: Mapping to Source Code Host /src Volume: /app
  19. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Volumes: Docker run command docker run -d -p 5000:5000 --name web2 -v $(pwd):/app [image name] Host Location: Working Directory Container
 Volume
  20. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker Orchestration Tools • Docker Compose • Link multiple containers • Docker Cloud • Deploy stacks of services • Docker Swarm • Scaling, high availability
  21. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker Compose • Define muli-container app • Use docker-compose.yml file • Link multiple containers • Use commands to manage whole app • Build, start and tear down services
  22. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Sample: docker-compose.yml version: '2' services: my-mongodb: image: mongo:latest networks: - aspnetcore-network
  23. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    mongoose: build: context: ./MongooseExpress dockerfile: mongoose.dockerfile networks: - aspnetcore-network Sample: docker-compose.yml (cont.)
  24. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    aspnetcore3: build: context: ./DockerComposeDemo dockerfile: aspnetcore.dockerfile ports: - "5000:5000" networks: - aspnetcore-network Sample: docker-compose.yml (cont.)
  25. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    networks: aspnetcore-network: driver: bridge Sample: docker-compose.yml (cont.)
  26. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Docker Compose Commands docker-compose build docker-compose up, down docker-compose start, stop docker-compose ps -a docker-compose logs docker-compose rm
  27. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Get the Bits github.com / tonysneed / DevWeek.2016.AspNetCore-Docker
  28. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek

    Contact Me • Email: [email protected] • Twitter: @tonysneed • Blog: blog.tonysneed.com