>> Hi, I'm Shayne Boyer,
and I'm a Principal PM on the Cloud advocate team.
>> I'm Lisa Guthrie, I'm a Program Manager
in Microsoft's Developer Division.
>> Great. We're going to talk about using Docker and.NET Core.
Lisa, I've been listening and hearing a lot about Docker.
What is it and why should I be
using it with my.NET Core applications?
>> Yeah, so I think of Docker as
a way of encapsulating everything that you need to
run an application such as a.NET Core
application including the application code itself,
as well as any frameworks or anything else,
packages that it depends on,
and of course, the underlying operating system itself.
So a Docker container is a way to
put that all together into one nice neat package,
to build it repeatably in a repeatable fashion,
and to put it wherever you need it.
Be it on your development workstation or in production.
>> So it sounds a little bit like a VM.
How is this different from a VM?
So VM is a machine where I would put all my stuff but I
obviously can't pick up my machine and move it around.
So how is this different from shipping
my machine around when it comes to packaging up an application?
>> Containers running on
the same machine can share certain components.
So a container is always going to be a little bit,
significantly in many cases,
lighter weight than the equivalent VM because, for example,
you don't need to have an entire copy
of the underlying operating system.
>> Okay.
>> Some of that is provided by the platform itself.
>> Okay. Awesome. So what I want to do
is I've got a Docker file here and a Docker file,
I think, is what we need in order
to describe what we need. You've mentioned that.
We need to have all of our dependencies
inside of this Docker image.
So I'm looking at a Docker file here.
In the first line I've got here,
it says from mcr.Microsoft.com/dotnet/core/sdk:3.0.
What is this telling me here in this first line?
>> So everything after that from statement is
the name or the path to the base image,
which is that underlying image
that your eventual container image will be built on.
In this case, you've specified that you want to use
a base image that has the.NET Core SDK version 3.0 on it.
>> Okay.
>> But you could use an earlier version of the.NET Core SDK,
you could specify an image that's running something else entirely.
But that particular image is out there,
it's published by Microsoft,
it's available for you to use,
and this line just brings that in so that you can use it.
It's very similar to having a pre-built VM that
has everything on it but much simpler and smaller.
>> So this is the base image,
we're establishing everything we're going to work upon.
>> Exactly.
>> So the next line we've got it says, WORKDIR.
So I'm assuming that means work directory,
and we're going a little bit of help here from our IDE.
We're establishing, it looks like,
sources where we're going to be working in.
>> Yes. So that's the directory in
this eventual container image that will contain stuff.
>> Okay. It looks like I have a copy command,
and if I look at the help,
it looks like we're going from a source
and then adds them to the file.
So I'm assuming we're copying
some files from our directory that we're in,
and then probably to that work directory, right?
>> Right. So at this point you have
an operating system, which is awesome,
you have the.NET Core framework or
the.NET Core SDK there on the container image,
which is also awesome.
But you don't actually have your application.
>> Okay.
>> So what this does is it copies
your application into that container image,
so that you can run it there.
>> Okay. Then the next thing we've got an entry point.
It looks like we're just doing what we would normally
do with a.NET Core application,
we're saying.NET and run.
>> Exactly.
>> So if I'm looking at the application,
let's go back to this line, this copy.
What exactly are we copying?
We're seeing we're copying dot or I'm
assuming my current directory is what we're doing.
>> Right.
>> In this case, it's just a console,
a Hello World application, right?
>> Yes.
>> So how will we go about building this?
I'm assuming that there's going to be
some commands that we have to run.
>> Yes.
>> So I think I'm going to drop out to our terminal.
>> Yes.
>> Run some commands. Now, I'm assuming Docker's got
a command line of some
that we're going to execute some commands, all right?
>> It does, yes. Since you're running on a Windows machine,
you've got Docker Desktop for Windows installed,
and there is a CLI that is logically enough called Docker.
>> Okay.
>> Which you can use and there's a Docker build command.
>> So much like our.NET CLIs,
we have our.NET and then a command, right?
>> Exactly.
>> I think that the first thing I'm going to do a Docker,
and then probably build.
Then I need to specify
a tag because I want to tag what I'm building, kind of name it.
>> Yes.
>> So we'll just call this Console,
maybe 101, and then I think the next thing we want
to do with probably say what do we want to pass in.
>> Right.
>> Where are we working? Well, plus
the dot here that indicate the current directory we're in.
>> Right.
>> So let's go ahead and run this and see what our output is.
>> Yes.
>> So it looks like we're sending
our build context to the Docker Daemon,
and that is that service that runs
from Docker desktop for Windows, as you mentioned.
But executing a couple of other steps here.
So let's maybe look at this a little depth.
Step 1 is that From,
so it looks like I've already downloaded that base image.
>> Right.
>> If it wasn't there, where do I
get that from? Where does that come from?
>> That's coming out from mcr.Microsoft.com,
which is Microsoft Container Registry.
It's a location where we publish the official Microsoft images for
things like Windows and.NET Core plus Windows, and so on.
>> Okay.
>> There are lots of container registries out there,
they're probably the best known is Docker Hub,
which is where a number of
well-known container images are published,
and you can also publish your own container images.
So for example, if your company had
a number or a certain framework
that was used in multiple applications,
you could publish your own base image.
That is this plus that framework,
and then that would just be there and available for people to use.
>> Great. Looks like we're setting our work directory.
>> Yes.
>> As expected and we're copying these files,
and now it says we've built and
tagged and it gives me some sort of a hash that I'm logging on.
>> Yes, exactly.
>> Then the end here tagged as we asked for Console 101,
and then it looks like a colon latest.
What does the colon latest here mean for us here?
>> That's a way that you can do versioning.
You can see, as well, in the MCR,
the very first MCR tag that's specifying SDK colon 3.0.
So that's the.NET Core version 3.0.
>> Okay.
>> You can have the same base image with different versions
and you can specify the version that you want to use.
So as you've done here in the from statement, you're saying,
"I want to use the version 3.0 of that.NET Core SDK."
You can also use latest,
which means I just want to use the latest.
So if for example,
3.1 of the.NET Core SDK were released,
automatically your application would start building with that.
>> Okay. Great. I'm going to
clear the screen give us a little more space,
and now that I have this container image that we've produced,
I need to do something with it.
See if it's out there.
So, I'm going to say Docker,
I want to run this image,
and I need to pass it the name of what we named it.
>> Exactly.
>> I believe it was Console 101,
and my expectation is that it's going
to run this particular container,
and I should get maybe Hello World,
should be the output.
Now, I'm not running this executable
Windows console app on my actual machine.
It's actually running inside of the container.
>> Exactly.
>> As you mentioned,
I can now package this up and move it around.
>> Right.
>> Back and forth between other machines.
>> Exactly. It'd be very easy to bring this onto my machine,
and even if I weren't running the.NET Core SDK,
everything that I need is in
that container image and so it would run just fine on my machine.
>> As expected, we got our Hello World.
>> There we go.
>> I feel like a super awesome
container developer now with.Net Core.
>> You are.
>> Great. So we've got our Hello World app running in a container,
but I feel like I'm jumping back and forth
between Visual Studio, going to the terminal.
I'm running some commands,
and then internal loop feels like not so comfortable.
It'd be great if Visual Studio had a way to help us out with that.
>> Yeah. In fact, we have some great container tools built right
into Visual Studio that make it
really easy to work with Docker containers.
>> Great. Let's check out the next video,
where we can jump in and look at that.