Once you've installed, open a new command prompt and run the following command:
Once you've installed, open a new terminal and run the following command:
Command prompt
dotnet
If the installation succeeded, you should see an output similar to the following:
Command prompt
Usage: dotnet [options]Usage: dotnet [path-to-application]Options:-h|--help Display help.--info Display .NET information.--list-sdks Display the installed SDKs.--list-runtimes Display the installed runtimes.path-to-application:The path to an application .dll file to execute.
Got an error?
If you receive a 'dotnet' is not recognized as an internal or external command error, make sure you opened a new command prompt. If you can't resolve the issue, use the I ran into an issue button to get help fixing the problem.
Create your service
In your command prompt, run the following command to create your app:
In your terminal, run the following command to create your app:
Command prompt
dotnet new webapi -o MyMicroservice --no-https -f net5.0
Then, navigate to the new directory created by the previous command:
Command prompt
cd MyMicroservice
What do these commands mean?
The dotnet command creates a new application of type webapi (that's a REST API endpoint).
The -o parameter creates a directory named MyMicroservice where your app is stored.
The --no-https flag creates an app that will run without an HTTPS certificate, to keep things simple for deployment.
The cd MyMicroservice command puts you into the newly created app directory.
The generated code
Several files were created in the MyMicroservice directory, to give you a simple service that is ready to run.
MyMicroservice.csproj defines what libraries the project references etc.
Startup.cs contains all the settings and configuration that are loaded when the app starts.
Controllers/WeatherForecastController.cs has code for a simple API that returns the weather forecast for the next five days.
WeatherForecastController.cs (shortened for clarity)
[ApiController][Route("[controller]")]public class WeatherForecastController : ControllerBase{ private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; private readonly ILogger<WeatherForecastController> _logger; public WeatherForecastController(ILogger<WeatherForecastController> logger) { _logger = logger; } [HttpGet] public IEnumerable<WeatherForecast> Get() { var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }) .ToArray(); }}
Run your service
In your command prompt, run the following command:
In your terminal, run the following command:
Command prompt
dotnet run
Wait for the command to display that it's listening on http://localhost:5000, and then open a new browser window and navigate to http://localhost:5000/WeatherForecast
Congratulations, you've got a simple service running!
Press CTRL+C on your command prompt to end the dotnet run command that is running the service locally.
Press CTRL+C on your terminal to end the dotnet run command that is running the service locally.
Install Docker
Docker is a platform that enables you to combine an app plus its configuration and dependencies into a single, independently deployable unit called a container.
If you already have Docker installed, make sure it's version 18.09 or higher.
Download and install
You'll be asked to register for Docker Store before you can download the installer.
By default, Docker will use Linux Containers on Windows. Leave this configuration settings as-is when prompted in the installer.
After installing Docker, you may be asked to sign out to finalize installation.
Check that Docker is ready to use
Once you've installed, open a new command prompt and run the following command:
Once you've installed, open a new terminal and run the following command:
Command prompt
docker --version
If the command runs, displaying some version information, then Docker is successfully installed.
Add Docker metadata
To run with Docker Image, you need a Dockerfile — a text file that contains instructions for how to build your app as a Docker image. A docker image contains everything needed to run your app as a Docker container.
Return to app directory
Since you opened a new command prompt in the previous step, you'll need to return to the directory you created your service in.
Since you opened a new terminal in the previous step, you'll need to return to the directory you created your service in.
Command prompt
cd MyMicroservice
Add a DockerFile
Create a file called Dockerfile with this command:
Command prompt
touch Dockerfile
Command prompt
fsutil file createnew Dockerfile 0
You can then open it in your favorite text editor.
You can then open it in your favorite text editor manually or with this command:
Command prompt
open Dockerfile
Command prompt
start Dockerfile
Replace the content of the Dockerfile to the following in the text editor: