A day with .Net

My day to day experince in .net

Docker Hello World with ASP.NET Core

Posted by vivekcek on March 3, 2018

I follow this rule “Never apply a technology in a project for the purpose of learning/using it”.
The above rule is applicable for Docker also, Use it if you are planning something big and have budget to rewrite after 3 years.
Sometimes you can keep things simple,thus by save money and time.

Anyway come back to my Docker journey.

1. I had to install a 64 bit version of Windows 10 and Visual Studio 2017.
2. Downloaded and installed Docker CE.
3. During the first start Docker enabled Hyper-V, that’s great.
4. Then i got an error message “You don’t have enough memory to start Docker”.
5. Go to Docker Settings from task-bar quick launch icon. Then reduced memory size to 1500mb.

6. You have to start Docker as Administrator.
7. Once your Docker is running, Open a Command Prompt as Administrator.
8. First i switched to my drive D and created a folder “myapp”.
9. Now issue below command to create an empty Asp.net core app.

dotnet new  web

10.Now issue dotnet run to run your app.

dotnet run

11.Check whetaher your app is running at http://localhost:5000
12. Now publish you app.

dotnet publish -c Release

13.Now inside this folder “bin\Release\netcoreapp2.0\publish”, Create a file named Dockerfile.
14.You can use notepad for that.
15. Place the below text inside your Dockerfile.

FROM microsoft/aspnetcore
WORKDIR /app
COPY . .
EXPOSE 80
ENTRYPOINT ["dotnet", "myapp.dll"]

16.Now build your Docker image using the build command.

docker build . -t myapp -f ./Dockerfile.txt

17.Once building finished check your docker images by this command.

docker images

18. Now run your Docker app.

docker run -p 8000:80 myapp

19. Your app will be running at port 8000

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s