Docker's .NET Conf

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

Welcome to Docker's .NET Conf lab!

This lab gets you using .NET Core in Docker containers. You'll experience compiling code, packaging apps and running containers, using the .NET Core 3.0 release.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("`Docker`")) -.-> docker/ContainerOperationsGroup(["`Container Operations`"]) git(("`Git`")) -.-> git/SetupandConfigGroup(["`Setup and Config`"]) docker(("`Docker`")) -.-> docker/DockerfileGroup(["`Dockerfile`"]) docker/ContainerOperationsGroup -.-> docker/run("`Run a Container`") git/SetupandConfigGroup -.-> git/clone("`Clone Repo`") docker/DockerfileGroup -.-> docker/build("`Build Image from Dockerfile`") subgraph Lab Skills docker/run -.-> lab-389186{{"`Docker's .NET Conf`"}} git/clone -.-> lab-389186{{"`Docker's .NET Conf`"}} docker/build -.-> lab-389186{{"`Docker's .NET Conf`"}} end

Clone the Source Code from GitHub

Clone the application source into /home/labex/project path:

Just click the text in these boxes to send the command to your terminal

git clone https://github.com/dockersamples/dotnetconf19.git

Now browse to the source code folder dotnetconf19:

cd dotnetconf19

In there you'll see a folder called src which contains the .NET code and a file called Dockerfile whch contains the instructions to build and package the app:

ls

Build the Application Image

The Dockerfile has dotnet commands to restore NuGet packages and publish the app:

cat Dockerfile

Even if you're not familiar with the Dockerfile syntax, you can kind of work out that this is a script to compile the app and package it up to run

You run the script with the docker build command, which produces a container package called a Docker image:

docker build --tag dotnetconf:19 .

You'll see lots of download progress bars, and some familiar output from MSBuild.

The final message Successfully tagged dotnetconf:19 tells you the image has been built and given the tag dotnetconf:19 - which is just the image name.

Run a .NET Core Container

A Docker image is a complete packaged app. You can share it on Docker Hub, which is how thousands of open-source and commercial projects now distribute their software.

Your image contains the .NET Core 3.0 runtime, together with the assemblies and configuration for the demo app.

You run the app by running a container from the image:

docker run dotnetconf:19

Scroll up to read the message from .NET Bot - that's your .NET Conf code!

If you want to learn more about what's happened here and how you can use Docker to build cross-platform apps that run on Windows, Linux, Itenal and Arm - check out this blog post:

Summary

Congratulations! You have completed the .NET Conf 2019 lab. You can practice more labs in LabEx to improve your skills.

Other Git Tutorials you may like