Step 1 - Start the SQL Server Image Container
Let us start!
First of all visit the hub.docker.com website and sign up to create an account for yourself. Take note of your login and password because you will need these credentials at the time of publishing your image through Visual Studio.
Next, open the Docker Desktop program and ensure that it is in its running state.
When the Docker Desktop Program starts, it starts all the necessary background services as well. These services are used by Visual Studio for creating and publishing the docker images.
Please watch the following youtube video:
Step 2 - Open the Find a Doctor Project
Next let us open our project. We shall use the project that we finalized earlier. Or you can download it from the attached downloads.
Open the project in visual studio 2019 or 2022 - both of them support publishing to the docker hub.
Step 3 - Create a Docker Image
Let us now create a docker image for our project!
Right the project to open the context menu. Click Add > Docker Support. This step is required for creating a Dockerfile.
You will be asked to select Linux or Windows. This is crucial. A wrong choice can waste your time in hours. We recommend that you should choose Linux - even if you are on Windows 10 Home Edition. So choose Target OS as Linux and click OK.
The process should start immediately. You can see the log in the output window. It will be a long process.
Wait for it to finish. It is a time consuming process. The container tools output will confirm a finish.
A Dockerfile will appear in the solution explorer. This file has no extension - it is named Dockerfile - and the name is case-sensitive. It contains all the layers for creating a docker image. As you might have seen - Visual Studio is very helpful in creating this file. Otherwise, it is very painful to type it manually.
Next, right click the Dockerfile to open a context menu. Locate the option "Build Docker Image". This menu option will help us create the final product - our docker image!
Click to start the process!
It will be a time consuming process. A rebuild will start. Visual Studio manages all the commands for us.
A long log of downloads takes place . . . but it finishes after a lot of patience.
Next open the command line and type the command
docker images to list all the docker images on your PC and, thus, to verify that our image has been created OK.
// list all the images to verify // that our image has been created docker images
If everything worked perfectly, then you should see myrazorapp listed as one of the repositories.
Step 4 - Publish the Docker Image
Finally, let us publish our image to the docker hub.
Right click the project to open the context menu. Find the "Publish" option and click it.
The Publish opens. You can see many publish targets listed here - Azure, Docker, Folder, FTP, etc., Select
Docker Container Registry. Click Next.
Here you can see many possible containers - Azure Container Registry, Docker Hub etc., Select Docker Hub and click Next.
A new window opens. You will have to enter your DockerHub user name and password. Click on Finish.
This is now the final step to publish. Click the Publish button at the top right corner.This will start the publish process.
Visual Studio executes the necessary docker commands, which makes it very easy for us.
The process takes a long time to execute. We can see a lot of build log output during the whole process.
A command window also opens during this. This window stays for a long time depending on the speed of your internet.
Finally, the process completes with the message - Successfully pushed docker image with tag 'latest'.
Step 5 - Verify on the DockerHub Page
Next logon to the DockerHub page.
If everything completed correctly, then you will be able to see your docker image listed on your DockerHub repository. Thanks!
This Blog Post/Article "(C# ASP.NET Core) Containerizing our Find a Doctor Project to DockerHub" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.