ONLINE-GAB 2020 – Hands-On-Lab (Working with Containers in Microsoft Azure)

Today Dan and I ran the Online Global Azure Bootcamp at Nashua Cloud.NET user group. Topic is to cover Hands-On-Lab on Containers in Microsoft Azure.

Meeting URL

https://www.meetup.com/nashuaug/events/269036707/

The Deck

Talk Description

Hands-On-Lab on Containers

  1. Create a Virtual Machine Windows Server 2019 Datacenter with Containers – Gen1 With RDP (3389), HTTP (80,443) open.  Alternatively, you can create a Virtual Machine with Windows Server 2016 or 2019 or Windows 10.  In this case after login to VM launch “Server Manager ->Add Roles and Features” and Install Hypervisor and Container.  A reboot may be required.
  2. From Server Manager–>Local Server–>IE Enhanced Security Configuration–>Off so that you can download files.
  3. Some links don’t work in IE, so download Edge or Chrome
  4. Download and Install Windows Container CE https://hub.docker.com/editions/community/docker-ce-desktop-windows/
  5. Launch the ex, and follow the wizards, in the first step click Ok to continue

    It will extract files and finish the install.If promted to restart please do so.

  6. Once re-started it will start the Docker when prompted enter Docker user id/password.  If you do not have one, create one in https://docker.com
  7. Download and Install .NET SDK 3.1 https://download.visualstudio.microsoft.com/download/pr/56131147-65ea-47d6-a945-b0296c86e510/44b43b7cb27d55081e650b9a4188a419/dotnet-sdk-3.1.201-win-x64.exe
  8. Download and Install VS Code https://aka.ms/win32-x64-user-stable

    with following options

  9. Create a new work directory example (c:/work/mvc1)
  10. Right-click on the folder (c:/work/mvc1) open VS Code
  11. Click Extensions
  12. Click Extension and install the following extensions

  13. Close VS Code and open again from your work folder (ex., c:/work/mvc1).

    This points onwards you may follow the steps from https://code.visualstudio.com/docs/containers/quickstart-aspnet-core

  14. Launch Terminal from Menu or Ctrl+Shift+`
  15. To create a new project >dotnet new MVC  (This will create MVC project files you can explore the folder structures, Models, Views and Controller)
  16. To Build execute the build command from the command window >dotnet build
  17. To Run the site, execute the run command from the command window

    >dotnet run

  18. Browse the listening URL
  19. Press Ctrl+C to stop
  20. To Debug, Open the HomeController.cs and set the breakpoint in Actions
  21. From the Menu, RunàStart Debugging
  22. Browse the listening URL your breakpoint should hit at this time
  23. To Stop, Run–>Stop Debugging
  24. To run in a container, you first need to build the container with DockerFile
  25. Press Ctrl+Shift+P, type docker file to add the docker file then select “Add Docker Files to Workspace” From the next screen select “.NET ASP.NET Core” From the next screen select “Linux”. If your Docker running in Windows then select “Windows”. To confirm go to your Docker then right-click to see the currently running container. You can switch from Linux to Windows or Windows to LinuxFrom the next screen, select YesFrom the next screen, change the port or leave default and press Enter
  26. From the File Explorer, Explore the files DockerFile, docker-compose.yml, docker-compose.debug.yml and .vscode\launch.json
  27. To Build Container, Press Ctrl+Shift+P then type Docker Build then select the Build Image to build the Docker image then it will show the status in the console, it may take a few minutes

  28. To view, the Image, Press Ctrl+Shift+P then type Docker View then select Image View
  29. To run the Image, from the view locate your image then Run or Run Interactive
  30. Once the Image is running, then browse to Inspect to see the IPAddress the browse to IPAddress
  31. Open a browser then Browse to IPAddress (Ex., http://172.23.71.172 )
  32. To Stop the Container, right-click and stop
  33. To Debug the container running local, click on the Debug icon then select “Docker .NET Core”
  34. To Debug, open .vscode/launch.json and add the highlighted line
  35. From Run–>Start Debug.  If you get a certificate warning, click Trust (required if you browse https)

    If you get the following error, close VS code, switch the Container to Windows then switch back to Linux then re-open VS code and launch start debug from Run menu.

    docker: Error response from daemon: invalid volume specification: ‘c:\work\mvc1:/src:rw’.See ‘docker run –help’.

    This time it will prompt for Share drive, click “Share it”

  36. The browser will be launched with localhost:32768 (your port may vary), you change the port in .vscode\task.json.  At this time it will hit your breakpoints.
  37. Publishing to Azure App Service. Follow the steps from https://code.visualstudio.com/docs/containers/app-service