Run an ASP.NET Core application in a Docker container

Download an ASP.NET Core Web API which includes a Dockerfile which allows you to build and run your application in a Docker container.

Software

This is the software that will need to be installed onto your machine.

Get the application working

You'll need to fill out the code example form. We will send you an email where you can download the code example.

The Web API and its references

The email will give you a link to a ZIP file which you can download and extract on your machine.

Inside the ZIP file, there is an ASP.NET Core Web API which is located in Web/RoundTheCode.DockerSample.WebApi.

C# coding challenges

C# coding challenges

Our online code editor allows you to compile the answer.

This references two class libraries called RoundTheCode.DockerSample.Application and RoundTheCode.DockerSample.Infrastructure. Both of these are located in the Libraries folder in the root directory of the ZIP file.

All of these applications run on .NET 9.

Install the Docker CLI

You need to ensure that you are able to run the Docker CLI. 

If you're a Windows user, you can either install Docker Desktop or Rancher Desktop onto your machine as both include the Docker CLI. If you're using Docker Desktop on Windows, you'll need to ensure that Windows Subsystem for Linux (WSL) is installed on your machine.

To do that, you go into Control Panel and Programs and Features. Select Turn Windows features on or off on the left-hand side and select Windows Subsystem for Linux if it's not already ticked. This will install it for you.

Build the Dockerfile

To build the Dockerfile, open up a terminal window and run a cd command to the directory where the Dockerfile is located in your extracted files. This will be in Web/RoundTheCode.DockerSample.WebApi.

Then run this command:

docker build -f "Dockerfile" -t roundthecode.dockersample.webapi:1.0 "../../"

Publish the Dockerfile

Ensure you run the same cd command as you did when building the Docker container. Then run this command:

docker run -p 38080:8080 roundthecode.dockersample.webapi:1.0

This should run the ASP.NET Core application on http://localhost:38080 from your machine.

More information

If you can't get the Dockerfile to build or run, or you want to know more about how it works, watch this video:

You can also learn more about how to write a Dockerfile by following the tutorial.