- Home
- .NET code examples
- Run an ASP.NET Core application in a Docker container
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.
- Visual Studio 2022. Version 17.12.0 or above. It will work with the free community version.
- .NET 9 SDK. Version 9.0.0 or above.
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.
Web/RoundTheCode.DockerSample.WebApi.
RoundTheCode.DockerSample.Application and RoundTheCode.DockerSample.Infrastructure. Both of these are located in the Libraries folder in the root directory of the ZIP file.
Install the Docker CLI
You need to ensure that you are able to run the Docker CLI.
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.
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.
Related pages