Join Tiberiu Covaci for an in-depth discussion in this video Publish the image, part of Deploying ASP.NET Applications.
- [Instructor] Once we are happy with the image and how it is working, we can start thinking how can we distribute that? And the easiest way to do that is by publishing the image. Now in order for us to be publishing the image, we need to do something else first, so let me show you what. We have two images here, docker image ls, so it will show us the images is available, one of them is hp plus and the other one is microsoft asp.net, but what we need to do is to tag that particular image with the specific name so that docker understands what to do with it.
So what I have to do is actually specify my user name, and then a version number. So I would say, docker image tag, so I want to tag this image, and I will call the original image is hplusports, the source image, and then the destination would be tibor19 slash hplussports. So tibor19 is actually my user name on hub.docker.com, and I need to specify a tag as well, which would be latest, and I press enter.
That will just add a tag to the existing image. I can look at it again with docker image ls, now I see that I have three different images, but if you look closely you will see that tibor19hplussports and hplussports have the same tag and the same image ID. So there is no difference between them. But now I can start publishing. So the way I do publishing is simple, as simple as writing docker image push, and then the name of the image that I want to push, so that would be tibor19 slash hplussports colon latest.
So I want to publish the latest version of this particular image, and by pressing enter, it will prepare the images, and then once prepared, they will be uploaded to hub.docker.com. And, if everything worked correctly, we have a digest here and let's go to hub.docker.com and see what we have in there. So, TB just published the image called hp plus, this is the name, the existing tags, latest, it's a compressed size of two gigabytes, and was last updated few seconds ago.
So how do we test that? Very simple. We go into a new machine, or, newly installed machine that has docker on it, and we can run docker image ls, so that will show us which images are available. So the only one available on this image is only microsoft aspnet. And, we can either do a docker pull, like we did with the microsoft asp.net one, or we can just say directly docker run. So, let's see. Docker...
Run... Dash d, because we want to run it in the background. Then dash dash rm because we want the container to be removed as soon as we stop it. Then we need to specify the port, dash p 8000 mapped to 80 on the container. Then we might want to specify a name for the container, minus minus name, and the name would would be myhubimage, because we want to use that image from the hub, and then we need to specify the image that we want to base this container on, so that would be tibor19, that's my docker ID, and hplussport as the name of the image under my user.
And then, again, optionally I can put the tag in latest or not, but in this case I won't put any latest tag, I will just specify the name. And what it does, it looks for the image, locally, the image does not exist locally and because of that again it will have to be downloaded. It's not as big as the first image, that's the asp.net one, it's just, I would think, one or two megs, actually two gigs, I would say, but most of is it's only differentially, so it's not very big size.
The longest one to take I think it's the first image to unpack, and then the rest of them will be much quicker. Once the image is downloaded, the container will be created, and once the container it's started, we will be able to test it. And the way we test that it's to just open another page and go to localhost8000 and see exactly the result of what we've done.
And this is it. So you might notice that actually works without any problems and the reason for that is because we are pointing to an existing database, so we just managed to take an existing container, an existing image actually of a container, from my machine and transport it into a different machine, by publishing it hub.docker.com, but this actually the very essence of Docker, it makes the work on my machine paradigm to go away, so it can deploy containers that work in any environment that you choose.
- Choosing a deployment strategy
- Installing IIS manually and automatically with PowerShell
- Deploying to IIS with Visual Studio
- Deploying to Azure
- Deploying to Docker