In this blog , We will see how can we build app using docker image and push docker image to docker hub repository.
1- Install docker for windows or mac.
2- Verify your .net and docker version. If you haven’t installed docker you can download from here.
3- Pull .net images from docker registry.
Step-1 Verify docker version using below cmd.
docker version
![](https://i1.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.36.36-AM.png?fit=688%2C511&ssl=1)
Step-2 Verify dotnet version
dotnet --info
![](https://i1.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.38.56-AM.png?fit=688%2C382&ssl=1)
Step-3 Create Sample application using dotnet
dotnet new sln --name dockerdemo
dotnet new mvc --output dotnetdemodocker
![](https://i0.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.47.18-AM.png?fit=688%2C214&ssl=1)
Step-4 Build project using below cmd
dotnet build
![](https://i0.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.50.42-AM.png?fit=688%2C371&ssl=1)
Step-5 run app using below cmd.
dotnet run
![](https://i1.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.54.53-AM.png?fit=688%2C265&ssl=1)
![](https://i0.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.56.10-AM.png?fit=688%2C265&ssl=1)
Step-6 Let’s containerise the app.
![](https://i1.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.58.10-AM.png?fit=688%2C404&ssl=1)
![This image has an empty alt attribute; its file name is Screenshot-2020-08-09-at-12-40-19-AM-png-2886×1934-1-scaled.jpg](https://i1.wp.com/asifwaquar.com/wp-content/uploads/2020/08/Screenshot-2020-08-09-at-12-40-19-AM-png-2886%C3%971934-1-scaled.jpg?fit=688%2C507)
Step-7 Create .dockerignore file . It removes unwanted folders to push to container.
![](https://i2.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.32.19-PM.png?fit=688%2C535&ssl=1)
Step-8 Now let’s build and run image locally using below cmd
docker build --tag asif1202/demodocker:v1 .
docker run --name v1 -p 80:80 asif1202/demodocker:v1
![](https://i1.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.36.14-PM.png?fit=688%2C329&ssl=1)
![](https://i1.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.36.36-PM.png?fit=688%2C272&ssl=1)
![](https://i2.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.38.24-PM.png?fit=688%2C272&ssl=1)
Step-9-Let’s push this image to docker hub repository. First we need to login to docker hub account and push our docker image to the repository by using below commands.
docker login
docker push asif1202/demodocker:v1
![](https://i2.wp.com/asifwaquar.com/wp-content/uploads/2022/04/Screenshot-2022-04-06-at-4.43.12-PM.png?fit=688%2C205&ssl=1)
![](https://i2.wp.com/asifwaquar.com/wp-content/uploads/2022/04/image-7.png?fit=688%2C345&ssl=1)