Docker .Net Core - Docker Blazor Webassembly [.Net Docker Tutorial]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hi. Welcome to CodingDroplets. In this video we  are going to see how to containerize a dot net application. Containerize have many features and  benefits such as being an immutable infrastructure, providing a portable architecture and enabling  scalability. The image can be used to create containers for your local development environment,  private cloud or public cloud. The topics covered in this video are. Adding a docker file to a new  or existing.net project. Publishing the docker image for our.net application to public repository  of docker hub and running that docker image in a different machine. Publishing the docker image to  a private repository and running it in a different machine. Sharing the docker image locally without  using any repositories will just save the docker image from the development machine and load it in  a different machine to run it. Before starting you should know few things. This video is part of a  series named micro service architecture. You can find the playlist link in the video description  to watch the other videos in this series. So let's get started. This is a demo project which I have  created for a previous blazor tutorial video for explaining the implementation of authentication  in blazor server project. I will show you how we can add the docker support for a project by adding  it in this project. The method is same for any type of .Net core projects. Those who need to learn  blazor development can find the playlist named blazor tutorial in our channel. First let's add  docker support for this project. Just right click on the project which you need to add the docker  support. Then go to add and click on docker support. Visual studio will ask you for the dockerfile  options. We can choose linux or windows as the target operating system. I prefer using  linux as the docker image size is much less compared to windows. But you can  choose it as per your need. Then click OK. Now you can see a new docker file got created in  the project folder. This docker image is exposing port number 80. So once we containerize this  project our application will be listening on port 80 in the container. Also now I can  run the project in docker and debug it. It will also download the needed images for the  application and create a new docker container to debug the application. Visual studio provides  the options to easily develop applications with docker support, debug with docker support and  deploy the docker container. Now you can see it is pulling "dotnet/aspnet" image. Currently  I don't have any docker images in my machine. Now there are two new images. This blazor server  auth image is the docker image of my project. You can see the tag as DEV. Visual studio creates this  image to create a container which will run our application while we debug it from visual studio.  Once the project is closed, then this container will get removed automatically. So I'll just show  you by debugging it from the docker container. This is the demo application. Just before that I  will show you a few things. Let me minimize the browser. Here visual studio shows the container  information in container window. The first tab is showing environment variables. Second tab is labels. Third is ports. Then volumes, files, logs and details. We can see all the docker container details  from here. Now let's see the application. It is just having a login functionality. We can  login with hard-coded user credentials. Both username and password are admin. Then it will show  some extra options in the menu and the home page. So we are going to publish this project  to a public repository of docker hub. For that just right click on the  project and click on the publish option. Now we need to choose the target. Here we  need to choose docker container registry. Next we need to select the specific target. We can  choose docker hub. To publish in docker hub, you should have an account in docker hub. You  can simply visit docker hub website and create an account by providing your email. If you are  connecting to your own repository, that means not part of an organization, leave the checkbox  for publish to a personal repository checked. If the repository is owned by an organization, clear the checkbox and enter the organization name. Then enter your docker username and  password for your docker account that has permission to access the repository  that you're connecting to and then click finish. Now the publish profile is created. You can see  the profile file inside the published profiles folder of the properties folder. I'll just  open the file for you to see the contents. We can change the publish settings from here. You  can change the configuration, target framework, deployment mode and target runtime if needed.  So let me click cancel button as I don't need to change anything. We can also change the docker  image tag by clicking on the edit image tag option. By default the tag will be "latest". Let me change it  to 1.00. Now let's click on the publish button to start building and publishing the image. Initially  visual studio will build our project. After that it will pull the needed images and create a new  docker image for our project. Once it is completed visual studio will execute the docker commands to  login to our repository and push the docker image. Finally you can see publish succeeded message in  visual studio. Let's open docker hub and check out the docker image. Now I am logged in to docker hub  and there is an image showing in my repositories tab. "codingdroplets/blazorserverauth"  is the repository name and you can see that the repository type is public. So this image can be  accessed by anyone you can also try pulling this image in your machine. We can see more details by  clicking on the repository. The available tags are displayed here. We have only uploaded 1.00. We can  provide a different tag for the same project and upload it. Then it will be also displayed here. Also we can create a readme content if needed. There is a separate tab named tags which  will list all the tags and image details. Then builds, collaborators - we can add  collaborators if needed. Then webhooks, settings. In settings we can see the option to make  the repository private. Also we have the option to delete the repository. Now let's try  to pull the docker image in a different machine. This machine is having ubuntu linux. I have only  installed docker in this. It is not having any other dependencies or libraries installed. I have  not even installed .Net runtime or any other frameworks. Now you can see there are no docker  containers running in this machine. Also there are no docker images. So let me provide "docker run" command to download the docker image and run it. Docker run command will automatically download the  image if it doesn't exist in the host machine. Next using "-p" parameter. We can assign a custom  port 8001 for the port 80 of the container. then "-d" for detaching the container. After that the docker image name of our project. We also need to provide the tag as we don't  have an image with latest tag. It will just show unable to find the  image locally. It will start downloading soon. It is getting  downloaded now. Let it get completed. Now it is completed. Let's list out the docker  images and you can see the image is downloaded. Let me also list out the running containers using  "docker ps" command. We can see the container is running and the port mapping also done. Now let me  open the browser and provide localhost:8001 and you can see the application is  working fine. All the functionalities of the application are working fine. Here all the  dependencies and libraries needed for our application are inside the container. We don't need to install  anything. It is very easy to deploy an application using docker. Next we are going to push a different  project to a private repository of docker hub. So private repositories can only be accessed  by you and the collaborators who have the permission. This is a blazer web assembly  project with .Net core hosted. This is also same kind of project which I have created to  demonstrate authentication in blazor webassembly. So in a blazor webassembly with .Net core  hosted project, the server project is the main project which we need to host. Let's add docker  support for this project as I explained before. The docker file got created. It will  do the same processes as before like pulling the needed images and building  the debug container etc. I'm just skipping these steps as we have already discussed it before. Now let's publish the project to docker hub. Choosing the docker container registry as the  target and dockerhub as the specific target. Then providing credentials for dockerhub  authentication. This time I am not changing the tag. Let it be "latest" tag only. Let's publish  it now. Finally we got publish succeeded message. Let's open docker hub to see the repository. Now  you can see the repository named "codingdroplets/bazorwasmauthserver". But you might  have noticed that the repository type is public. We'll change it now from the settings tab of the  repository details. I am clicking on make private button. It is asking me to enter the project  name for the confirmation. Let me copy-paste it. Now the repository has become private. In the  repositories page you can see the type. So now we have one public and one private repositories. Now the main difference is in pulling the private repository image. I'll show you how it is. So  let's try to pull it to this ubuntu linux machine. In the same way as before. I am providing "docker  run" command then assigning port 8002 as we have already assigned 8001 for our previous application. After that "-d" to detach the container. Then the repository name. We don't need to provide the  tag here as latest tag is the default one. Now let me hit enter and this is not going to work let's  see what the error message we are getting. You can see that pull access denied. Repository does not  exist or may require docker login. You must login to docker hub before pulling a private repository  image. To login I can provide docker login command. Then "-u" to specify the username. Now it  will prompt for the password. I can enter the password here to login. If the user credentials are  valid you can see a login succeeded message here. Now I can use the same previous command to pull  the docker image from my private repository and run it. Let's open a new tab in the browser and try  to open the URL. The application is working fine. So this is how the private repositories work. Next  we are going to see how we can share docker images locally without using any repositories. You can  just copy the file from one machine to another and create the container. So let's see how it is. As  we've done before just add docker support to your project. After that just open terminal by right  clicking on the project. You can even open command prompt or powershell from the start menu and  navigate to the solution folder. I am just listing out the images by using "docker image" command so  it is having the images created by visual studio. If I execute "docker ps" command, you can see a  container is running. This is just created by visual studio for us to debug the application. This  container will get removed if we close the project. So let me close the project. Now you can see  that there is no project opened. The solution explorer is blank. Again I am running "docker images"  command and the list is same. But when I list the containers by using "docker ps" command, you can  see the container got removed. Now let's create a new docker image from the docker file. Let me  list the files in the folder using "dir" command and you can see we have the dockerfile in  the same folder. Now we can provide "docker build" command to create a new docker image. I   am providing "-t" parameter to set a custom name and tag for the image. That's it needed. You can see now the image is getting created. It got completed. Now let me list out the docker  images. There is a new image available in the list and that is the one which got created now. Now let  me move to another folder in which i need to save the docker image. I can provide docker save command  along with the image name to save the docker image as a TAR file. Also providing "-o" parameter  to mention the output file name. I'm saving it as "blazorapp.tar". Let me list out the files to see  the created TAR file. I'll show you the file in file explorer as well. Here you can see the file.  Now let me copy this file to the other machine and will show you how to use it. I have copied the TAR  file to folder named "docker-image-backups" in the documents folder. Let me list out the files and you  can see the file here. Now we can use "docker load" command to load the docker image from the TAR file. Then provide a less than symbol and name of the file. It is showing the loaded image message now. Let's check it by listing out the docker images. Here we have the docker image loaded from  the file. Next we can just provide "docker run" command to create the container and run it. I am  providing port 8003 using "-p" parameter. Then "-d" parameter to detach the container. Then  finally the Image ID. Just first few characters of the image id are sufficient. The container got  created. Let's list out the running containers. Here we have the container which is mapped with  8003 port number. Let's try to open the URL in a browser. You can see the application is working  fine. This is how we can use "docker save" and "docker load" commands to share it as a TAR file. Let me also show you two more docker commands. First let me stop all the running containers using "docker stop" command. Now I am providing "docker system df" command. It  will show us the total numbers, size consumed by images, containers, volumes and build cache. All  the details. Next I'll show you one more command that you may find helpful in development machines.  Please be careful. Don't do this in production machines. It is just for clearing everything using  a single command. "docker system prune -a" will wash out everything from the docker. It  will ask for a confirmation before continuing. So let me confirm and everything got deleted now. Let me provide "docker system df" command again and you can see all usages are showing as zero. So that's it for this video. Hope you liked it. Please subscribe, like and share this video. See you all in the next video. Thank You!
Info
Channel: Coding Droplets
Views: 7,279
Rating: undefined out of 5
Keywords: docker blazor webassembly, docker .net core, .net docker tutorial, docker asp.net core 3, docker asp.net core tutorial, docker .net core api, docker .net core microservices, docker in .net core, docker secrets .net core, docker dotnet core api, install .net core api in docker, .net core docker, .net core docker debuging, docker .net core debug, docker asp .net core, docker for .net core, deploy .net core to docker, .net core docker container, dotnet core docker example
Id: ZCJKiwTMTSs
Channel Id: undefined
Length: 17min 0sec (1020 seconds)
Published: Mon Apr 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.