Problem
How to run my first .net core 2.0 console application in windows10 docker?Background
This exercise is for beginners who want to understand Docker fundamental tenets and run their first .net core 2.0 application in windows10 docker.Solution
Prerequisites
Use the below link to setup docker on your Windows10 laptop/desktop.
Steps
1. Create new "Console App (.Net Core)" project using "File >> New >> Project" menu.
2. It creates a new project (CoreHelloWorld) with "Program.cs" class with the following lines of code. Execute the project and make sure it works. 😀
3. Make sure docker is running in "Windows Container" mode on your machine. If not, then switch to "Windows Container"
4. Now your application must be packed with its dependencies into a folder for deployment. You may do this with two options.
a. Run "dotnet publish" command from project root directory
b. Select (CoreHelloWorld) your project, from the context menu, click "Publish". This will open a popup window, from the popup window select "Publish Target" type "Folder" and specify folder name.
Now files are published into specified folder
5. Add a new file (text ) to your project, then name the file as "Dockerfile"
To know more about "Dockerfile" and image refer the following link
6. You may copy the following contents into "Dockerfile" and do the necessary modification.
FROM microsoft/dotnet WORKDIR /netcoreapp2.0 COPY /bin/Debug/netcoreapp2.0/publish/ . ENTRYPOINT ["dotnet", "CoreHelloWorld.dll"]
7. Now the "Dockerfile" is ready, Now run the build command. This creates a Docker image. "-t" you may provide a friendly name (lower case) to Docker image.
docker build -t corehw .
"build" command expects the path of the image file. If you are referring the local Dockerfile then don't forget to add "." at the end.
8. Using the following command, make sure the newly created image is available.
docker image ls
9. Using the following command, you can run the Docker image.
docker run --name corehwcontainer corehw
You may also run the Docker image without specifying the "--name" parameter. In that case, daemon generates a random string name for the container. It's always good practice to run with the name.
Using the following command you can list all processes.
10. Both image and container can be deleted using the following commands
Using the following command you can list all processes.
docker ps -a
10. Both image and container can be deleted using the following commands
docker rm corehwcontainer docker rmi corehw
It is very good blog and useful for students
ReplyDelete.Net Online Training Hyderabad