A day with .Net

My day to day experince in .net

Archive for March, 2018

Pushing your local docker image to Azure Container Registry

Posted by vivekcek on March 18, 2018

In the last post, i wrote about how can we create and run Docker image locally.

Docker Hello World with ASP.NET Core

Today, i will show you how can we push this local Docker image to Azure Container Registry.Azure Container Registry is a private Docker Registry like Docker Hub, to which we can store our docker images.The Docker images stored in this registry can be deployed to a kubernetes cluster easily.

So what are the tools we required.

1. Docker CE.
2. Azure CLI.
3. Azure Subscription.

I am planning to use the Docker image created in the last post. So refer that post to create a docker image.
Before starting make sure Docker is running in your PC with admin privilege.

1. First go to Azure Portal.

2. Search for Azure Container Registry.

3. Create a container registry.Note down the name of the registry (Ex:vivekcek).

4. Once the registry is created, from the Acess Key tab note down the login server name (ex:vivekcek.azurecr.io).

5. Now open the command prompt as Administartor(Azure CLI must be installed).

6. Issue below command to login(Docker must be running for login).

az acr login --name vivekcek

7.Now list the available images in your docker.

docker ps

8. Now tag myapp image.

docker tag myapp vivekcek.azurecr.io/myapp:v1

9. Now push the taged myapp image.

docker push vivekcek.azurecr.io/myapp

10. Now in azure portal under Repository tab see your image.

Posted in Azure, Docker | Tagged: | Leave a Comment »

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

Posted in Docker | Tagged: , , | Leave a Comment »