This post demonstrates how to dockerized .Net Core Application and push the image to Azure Registry or Docker Hub using the VS Code. Below is the structure of the project that will be used to show the demo. If you want to know how to add a docker file in the project then click here.
You can download the DockerFile code from below and change it as per your project name.
Build Docker Image
To build a Docker image, open the command prompt, and navigate to the project folder. The below command creates a docker image of your application named demoimage.
docker build -t demoimage .
You can see the docker image has been created with the tag latest.
Verify the application is running fine within the container. Use the docker run command to run the application as a container.
docker run -d -p 8081:80 myapp demoimage
Open the web browser application on port number 8081 and you can see your application is running in the container locally.
Push Image to Azure Container Registry
I have already created an Azure container registry. You can follow the instruction here to create it if you have not created yet. First, you have to log in to your Azure registry. Use docker login command with your login server name of Azure Container Registry and provide the username and password. You can find username and password under the 'Access Key' tab of registry on the Azure portal.
docker login yourLoginServer.azurecr.io
You have to tag your image with your registry name.
docker tag demoimage yourLoginServer.azurecr.io/demoimage
Now you are ready to push the image to the registry. Run below command
Switch to the Azure portal and you can see the image in Azure Container Registry.
Push Image to Docker Hub
Log in to Docker Hub using your Docker Hub credential.
Tag the image as per the docker hub registry.
docker tag demoimage/demoimage:1
Push the image using the below command and then verify on Docker Hub.
docker push sakaldeep/demoimage:1
The next post will demonstrate how to run this image/application on Azure Kubernetes Service (AKS). I hope you enjoyed the post and it gave you fair information to start with. Please visit sakaldeep.com.np for more posts.