Well, let's get this party started, shall we?
I'm going to walk you through using Docker containers.
Specifically, we'll do Windows Server containers in Windows Server 2022.
A lot to do here, so let's get started.
I'm going to bring up VS Code and mention that in order to work most efficiently
in this context there's some extensions here on the Extensions gallery that
you'll want to install just so that you're covered.
There's an official Microsoft Docker extension that gives you
Dockerfile syntax and this kind of stuff.
Some other extensions you'll want are the PowerShell extension
to give you language support for PowerShell.
We're going to be working with the Azure command line interface,
so you'll want the Azure CLI tools as well.
And I think that's good for now.
So let me collapse my extensions, let me right‑click and do a Close to the Right.
And, of course,
I give you this PowerShell file along with the
supplemental work files in the exercise files.
So what I've got here is first of all taking you from soup to nuts.
Let's say we want to set up this Windows Server 2022
machine as a Docker container host.
So what we'll want to do, if we want to support Hyper‑V containers,
on line 4 here,
we'll do an Install‑WindowsFeature to install the Hyper‑V feature,
and that'll require a restart.
To set up the server for container support,
there's just a couple of commands here.
Assuming that your host is connected to the Internet,
we'll want to install the DockerMsftProvider from the PowerShell Gallery.
That will then give you the ability to tap into packages like you see here on 8,
line 8, Install‑Package Name docker.
Both of these commands are going to install the
containers feature on your Windows Server,
but line 8 in particular is going to install the Docker
CLI and the build tools that you need,
and also it'll install the Docker Service on your system.
After you install those binaries, you'll want to definitely,
in fact, you have to restart your computer,
and then you'll find that the Docker Service should already be running.
Let me quickly check that on my terminal environment.
I'll do a get‑service Docker.
Yep, so my Docker Engine is running here, I'm all set.
So at this point, we're ready to rock and roll.
So what we're going to use is, for the most part,
the native Docker command line tooling,
and what we can do is pull images directly from the
Docker Hub by using docker pull, and then you just need the syntax for the image.
And you can go out to the Pluralsight library to get
details on working with Docker Hub.
It's hub.docker.com.
You'll need to sign in with your Docker account,
it's a free account,
and that will give you access to all of the public image galleries.
Microsoft has a whole bunch of them, as you can expect.
So pull is going to download the image to your system,
and then you can run docker images to get a list of
all images available on your system.
And I've pulled down both the nano server and the IIS image.
Nano is just one of the core base images.
It's the thinnest, slimmest one.
An IIS is a servercore image that already has the Internet Information
Services server role installed on it for convenience.
And then here this shows us how we can just start
to go ahead and run containers.
So what are we doing here?
It looks like docker run it.
Now it is an alternative to ‑d.
If you want to run a container in the background,
you'll detach it from your console.
You just do docker run ‑d.
If you want to actually sign into it, in that case you'll do it.
That's going to bind you to the terminal.
Now let me see here.
I don't actually have an image called nano1,
so I'm going to do a fully qualified path here.
Now this first piece is the label of the container,
and this is just the default one.
Yes,
you can rename the images so you don't have to type
those long paths if you don't want to.
And then the tag syntax is to do the label,
colon, and then this could be a version number,
and ltsc is a long‑term support Windows Server 2022 image.
Alright,
so we're going to start an image interactively using this nano server image,
and then here's the exam alert with regard to isolation.
You do ‑‑isolation=, and the options are either going to be hyperv or process.
And it looks like I done goofed,
and I'm going to leave this in the recording rather than snip it out,
because life isn't perfect.
I forgot about this.
This name is where you can give your container a friendly name.
So it looks like I was referencing the container initially just fine,
and I said no nano 2, there's not, yeah,
well, that's just the friendly name.
I'm going to call this servernano,
and this just gives your container an easier handle for you to interact with,
okay.
So let me clear the screen.
Let me right‑click, run the selection.
Another value proposition of containers is that they start almost immediately.
You notice that in less than 3 seconds we're now at a C prompt.
If I do a hostname, this is just the ID of the running container,
but it is a CMD session in this nano image.
And if I do a Directory listing, there's a Users folder and the Windows folder.
You might be thinking, well,
what if we wanted to install software to run on this image?
That's where we get into the build process,
and I'm glad that I thought of segueing that way,
because it makes a lot of sense.
By the way, a common newcomer question is,
once you're in the terminal session like I am,
how do you get out of it?
You can't just do an exit.
It's kind of annoying.
You do a Ctrl+P and Ctrl+Q.
And if you try to do that in VS Code,
there are already key bindings that are mapped to Ctrl+P and Ctrl+Q,
so you'll need to go into your Command Palette and go into key bindings.
I give you some instructions in the exercise files
if you want to know about that.
But now if I do a hostname, we should see I'm on arc2,
so I'm detached from that container.
I can see my running containers by doing docker ps.
And if I want to get rid of this container,
I'm actually going to not only stop the container,
I'm going to delete it.
I'm going to do a docker rm ‑f,
and then I can reference the name of the container,
servernano.
And now if I do up arrow a couple of times, docker ps, it's gone.
Now I do have a note on 21.
I'm not going to go into it in this demo,
but you should know that Windows Admin Center also has a
graphical overlay for working with containers.
Check the exercise files for some more details on that.
I'm going to stay with the command line interface,
because this is much more likely what you'll be quizzed on on your AZ‑800,
but just know that there is a nice graphical front end to the containers
feature that you can add into Windows Admin Center.
Alright, so the way you'll set up your build environment is as follows.
I already have it set up in VS Code.
I've created a work folder called iis‑website.
My goal here is to deploy a container that has IIS installed,
and not only that, I want to pre‑stage it with content.
So I have in my work folder a file with no extension
called Dockerfile with a capital D.
Now the reason it shows up with a correct icon here is
because I set a custom File Icon Theme.
These are just extras.
I love VS Code,
and I will take any and every excuse I can to teach people about it.
And the reason why we get syntax highlighting and
auto‑complete and snippets here, it may be small on your screen,
but in the lower right corner, the Language Mode is set to Auto Detect.
And because I have the Docker extension,
VS Code is recognizing this as a Dockerfile,
so you do get IntelliSense and all that good stuff.
Now this is about as simple of a Dockerfile as I could possibly think of.
You always start with a FROM where you get your base image.
In this case,
we're going to grab the servercore/iis image that
I've got already on my machine,
and then we're going to use the ADD keyword to take the wwwroot
directory that I have in my work folder and copy it into the
container under the path root /inetpubwwwroot.
And you know if you've worked with IIS that that's the
default content directory in IIS.
So that's how that works.
And in wwwroot, I just have an index.html file.
Actually, it looks like it doesn't have any content in it right now.
Let me fix that.
And this is just a hello world page, as you can see.
It's got a head and it's got an h1,
just to let us know as a proof of concept that it's working.
But you presumably would have all the scaffolding,
the file system artifacts for your website staged in that folder.
Now just for completeness,
I have a couple other Dockerfiles that are a bit more complex.
Here in this example we're grabbing it looks like a
servercore as our base image,
and then we're using the Docker CLI RUN command to
run a command into the container,
so this would allow us to do things like setting up server roles,
downloading stuff, etc.
There's an EXPOSE keyword, where you can expose ports,
networking ports,
and then you can define an ENTRYPOINT for that container as well.
Lastly, I have a much longer sample Dockerfile here.
Again, this looks like it's starting from the servercore base image.
We've got several RUN commands to enable features.
Again, there's not too much to this,
but I just want to transmit the fact that in these Dockerfiles we're using a
domain‑specific language from Docker that allows us just to declaratively
define how we want the resulting image to look.
So let's come back to our containers.ps1.
Let me clean up my tabs.
And the way you do this, assuming you're in that directory,
which I'm not actually, so let me do a,
I've got a neat extension here that allows us to
copy file path to the clipboard.
So let me copy the current file path to the clipboard,
and let me do a cd, and then I want to cd into my iis‑website.
We want to be in the context of our build folder,
in other words, the folder that our Dockerfile is in.
And what we do here is docker build,
and then I'm going to add a tag with the t keyword,
and I'm going to call this docker build ‑t tim,
that's me, the owner, /iis:, and then I'm going to do v2022,
space, and then the path to where your assets are.
I'm in the current directory.
You don't have to be, you just specify the correct path.
I put myself in the current directory to make this work.
So let me right‑click, run the selection, and there you go.
So if I do a docker images, I should be able to see that.
Yeah, right up here, tim/iis:v2022, and each image gets its own unique ID.
Now as far as the networking stuff,
we don't need to get too deep in the weeds there.
We can see the Docker network topology on our host by running docker network ls.
And I have a Hyper‑V External Switch that I've set up for my server.
If I go to Virtual Switch Manager,
I have my External Switch that's bound to the network interface on the host.
That's called transparent networking in Docker syntax.
You can create your own transparent switch by doing
docker network create d transparent, and then giving it a friendly name.
But I'm actually going to reference the mapping that's
already here to my Hyper‑V External Switch,
which, as you see, is using the transparent driver.
Lastly, to run our new image, we can do a docker run,
and I'm going to call this az800‑iis to give it a nice user friendly name,
d for detached, isolation is hyperv, network maps to the desired network,
p 80:80 means that I'm mapping port 80 into the container,
and out of the container on 80, and then lastly,
the name of the container is tim/iss:v2022.
There, and let me right‑click this and run the selection.
Now the problem here testing this is that because we're doing External Switch,
then this container is going to pick up an IP address
from my host network's DHCP server,
so it's going to be a little bit of work to try to track down
that IP address that I don't want to mess with.
So let me start over, let me do first of all a docker rm ‑f az800‑iis.
And then let's start this again just using the default NAT networking.
I'll call this az800 iis2, run this selection.
Now if I bring up Edge and make a connection to localhost,
I can see the page right there.
Proof of concept, right?
Let me do again a docker rm f az800‑iis2.
Now you don't need to do docker rm ‑f.
That just assumes that you want to stop and kill the container.
We could do docker kill az800‑iis2, and that would stop the running container.
If we do a docker ps, there's nothing running,
but if I do a docker ps ‑a, I can see that it's still there,
it's just stopped, it's Exited. We can do a docker rm to get rid of it, and were cleaned up.