Docker container renders a lightweight way to separate your application from the rest of the host system, utilizing the resources enabled.
Create and publish a “Hello World” .Net Core App.
Create and configure Dockerfile for .Net Core.
Build a Docker Image.
Create and run a docker container.
Fire a new command prompt in “Administration Mode” and create a new .Net core application using the following command.
dotnet new console -o App -n NetCore.Docker
The command will generate a new folder named “App” and create a Hello World .Net core application inside it.
To test the console application, run below command.
The preceding command will output Hello World onto the console.
Before containerizing the app, first it must be published. Create a publish build of a .Net Core application run below command with the “Release” parameter.
dotnet publish -c Release
The preceding command will generate a published version of Hello World application into the following path.
After necessary .Net Core application setup is ready and published, let’s move on to create a docker file.
Create a file named “Dockerfile” in the App folder directory. Open the created file and place the below fragment into it & Save.
The above line instructs Docker to use .Net Core Runtime environment, which is relevant for .Net Core application created above.
Docker will process all lines inside the Dockerfile. The “.” character in the build command tells Docker to use the existing folder to find the Dockerfile.
docker build -t counter-image -f Dockerfile.txt .
To verify images list, run below command
After a container is running, you can establish a connection to see the output. However, to create a container applying below command.
docker create --name core-counter counter-image
Run a docker container
Below command perform two things, first, automatically use the command prompt to connect to the container, and then when the container completes the task, remove it.
docker run -it --rm counter-image
Thank you for reading. Keep visiting and share this in your network. Please put your thoughts and feedback in the comments section.