Wednesday, February 4, 2026

Containers for Existing .NET Apps Part 1

[Music]
hi welcome to visual studio tool box I'm
your host Robert Greene and today we're
gonna talk about containers and joining
me to do that is a dd-do guard hey
everyone how are you good thanks for
coming on thank you we've done
containers a few times in the show we've
had episodes on docker we just did as
part of the smart hotel 360 series dive
on the back-end services which are all
containerized micro services but what I
wanted to do is kind of start from
scratch right go back to the beginning
if you will and talk about what
containers are and what some of the
tooling is in visual studio to help
because there is quite a bit of tooling
that helps and then approach it from a
different angle not so much the fancy
modern micro services you know where
some are in.net core and others are in
Java and they're orchestrated in
kubernetes and all that which is you
know good stuff to know but what if I'm
just somebody who's building and
maintaining his built and is maintaining
all right classic dotnet applications
days is p.net web forms or MVC or a wind
forms or WPF app that talks to WCF to
talks to a sequel server right what a
containers have to do with me because it
turns out the answer is a lot yep for
sure um yeah that's a great point so
let's take a look here at what the term
modernization actually means and where
containers really fits into that so
really we're talking about here existing
absent services we're talking about so
applications built with net framework
usually on Prem and we want to make sure
that we can move those to the cloud
right without necessarily having to
rewrite it as a dotnet core app exactly
can do if you do decide a requirement no
and there's much easier ways to move it
to the cloud if you don't want to spend
the time rewriting it in dotnet core so
the first option you could do would be
to migrate it so this really means
making it cloud infrastructure ready
which is really just Rijo stting in VMs
so here you have don't code changes
really easy but you use VM
which is kind of the more traditional
route right when we're talking about
modernizing you can do this in a couple
different ways one is making a cloud
DevOps ready and this is where
containers come in so containers really
make it more portable lightweight easy
to deploy and more DevOps ready and here
again minimal very minimal code changes
so you don't really have to reaaargh
attacked your app at all it's really
just adding some extra few lines for
container support okay which is pretty
easy to do and I'll go through that in a
little bit and or you could cloud
optimize your app and that's kind of
what you were talking about before with
rewriting your app we are connecting
your app into dotnet core may be
utilizing micro services but obviously
that will require a lot more work so
containers can be more of an easy step
in between though it's a first step it
may be the only step you need to take
yeah exactly you don't have to go fully
to micro services if you don't want to
okay and let's take a second for and
talk a little bit about VMs versus
containers just so people can get a
sense of what the differences are
between the two so in a container what's
different is that you're sharing an
operating system kernel and you're
really deploying the containers with the
binaries libraries and the application
and that's what makes it so lightweight
and so portable versus a VM you actually
have the operating system that for each
one right it's called a virtual machine
for a reason an entire machine
virtualized so it's everything from the
base operating system on up so they're
huge they require huge amounts of disk
space
there's certainly scenarios where that's
good
they're not exactly portable not exactly
lightweight the container is you take
the application and all of its
dependencies and that's what's in the
container and then it runs on the
operating system which already exists
exactly Windows server or of course no
server in the cloud
yeah yes yes so you could have Linux and
Windows so today we're focusing on
Windows that's just because we're
talking about dotnet framework
locations so you'll have to use windows
containers but yeah you can also have
yet to use meniscus yes to use Windows
containers exactly but if you wrote a
dotnet core application and wanted to
containerize that you could pick if you
want to choose Windows containers Linux
containers whatever you actually want to
use yep Linux containers a little bit
more lightweight that can be faster at
the moment a little bit where they work
a little bit better with kubernetes
although great windows support is coming
on the other hand I don't know nothing
about Linux I know a lot about windows
so you know there's a benefit to
choosing the container that's the
operating system you know about very
true right so let's go into talking a
little bit about docker just too many
people are familiar with docker so
docker is basically a container platform
provider and it helps you automate your
containerization so you can easily
deploy your app season containers and so
Microsoft actually has a set of images
hosted on docker that makes this really
easy for you
so if you go to docker hub here you can
see that Microsoft has published all
sorts of images so you have your Windows
server core image your dotnet images you
have your asp.net images so here's where
you can find kind of all of the images
that these are starting points exactly
take that image and then you add things
to it like your application or
additional functionality that you want
to added you can start out with a
stripped-down container and then add
more things to it you could just choose
the the asp net or the ASP core image
which already has asp.net core running
and then you can just do nothing more
than put your app into it and then of
course you can make any other changes
you need to it to add functionality or
restrict functionality right you don't
have to start from scratch no you don't
have to start from scratch which is
great and all of these have
documentation associated with them which
is even better because it makes it even
easier to get up and running on a very
regular basis correct definitely um so
let's talk first before we go into the
demos about why you want to containerize
your app because it's the cool thing
doing it exactly that's the only reason
you should do it so modernization in
general can be useful for improving
agility growing your applications
lowering your IT costs say you have an
on-prem database that you want to move
to the cloud really modernization in
general is about lowering your total
cost of ownership containers in
particular are useful because as I
mentioned before you don't have to re
are katuk to your code so that makes
things a little bit easier for you
there's less of a learning curve
less code required lower deployment
costs improved productivity improved
DevOps ability and portability which is
what we talked about with containers
versus VMs I also give you some
act as kind of a I know it's rightward
almost l-like a firewall between you and
the rest of the machine right so you
could have a web app running on a
machine that you wrote on dotnet 3:5 and
you're leaving it there because it works
fine but then people keep making changes
to that machine and new versions come on
or new libraries come in and now your
app is subject to whatever's going on on
that machine so right you know how many
times is your app broken because
somebody fiddled with the server you
stick it in a container it's fixed that
container runs on that machine then
people can do whatever they want to that
machine as long as they don't you know
take away the ability to run a container
and your app will never be affected by
that and if you need to make changes to
your app in the container then you go
ahead and do that
whether it's update to new version of
the framework or apply different patches
or whatever but you get this isolation
that's the what I was looking for you
get an isolation and the ability to move
it around right oh this machine's going
down for three weeks we're gonna replace
it with a new machine can you get your
app up and running on this new machine
yeah right if you have to then go and
install on that machine you know that
can be a bit of a nightmare oh you say
yeah here's the container run it done
easy yeah yeah I mean another point
there is really dev test environments as
well so you hear a lot of people who are
like I worked in testing on my machine
weird on my machine but somehow this
just yeah doesn't work in production
right so that's also solved we use this
app twice a year right because we have
our annual poll or we have our annual
raffle twice a year so you just want to
you know necessarily want that up having
to run all year you spin it up when you
need it and you take it down containers
make it really easy to do that as well
so there's a lot of things agreed um so
let's get into some demos so I can
actually show how this works in visual
studio so let's take a look at this
first scenario here so a common scenario
might be to have a web application and
this could be an MVC F this could be a
web forms up and you could containerize
this you could have it talk to a
sequel server also in a container for
the purposes of the first demo we're
just going to stick with container izing
just the MVC portion of the app okay you
have to put in some additional
dependencies in to talk to the sequel
server which I'll show you in the second
demo which is a little bit more complex
but let's start with the basics alright
so if we go to our legacy MVC app and
move the word legacy legacy means
existing apps that are running the
business today
exactly existing business applications
yeah so I've started this up already and
this is basically an eShop which has a
bunch of different catalog items and you
can manage the catalog from this web app
here so you could create new items you
could edit delete do whatever you need
to see meta log framework three five
four four probably four something
probably four seven it's cooked how was
that recent okay yeah we just made these
recently I think oh yeah we update them
pretty regularly but it could be older
if it needed okay
doesn't matter what right what framework
version per se so as you can see this is
running locally just on my machine here
so if we go back to the application in
Visual Studio and I want to add docker
support all I need to do is right click
here and say add now before you click
that mm-hmm not that this is hasn't
happened to me like every day first of
all you need docker installed on your
local train yep and you need it running
yes that's a great point yeah
so I had a dollar for every time I
either built this project or tried to
add doctors support before I had
actually started docker yeah I could
retire yeah that's a really good point I
automatically have it up and running at
the time so I forget that that's a
critical step in the process you can see
by this little icon down here it's up
and running another point there is that
you see here it says switch to Linux
containers so right now I'm running
Windows containers and you have to make
sure you're running Windows or Linux
containers whichever one you want to
choose okay so if we go into here and
say add darker support it's going to
auto generate a few files for us and we
can walk through each of them talk a
little bit about what they're doing so
this first is the dockerfile and this is
basically describing the environment
that your app is running in so the
important point here is that it's using
this Microsoft asp net image yeah so
this is basically the recipe for how you
build this container it says if you
haven't already downloaded it to your
computer which can take a while go to
docker hub and get this particular image
window server core version 1709 with
asp.net 4.7 not one that's pretty new
right right so go get that file which is
large it is pretty large so the first
time you run this it actually takes a
little bit of time to download that
image and make sure it's on your machine
once it's already there and unless you
delete it and it's pretty quick to
startup right but yeah the first time
it'll be a little bit yep lengthy you
also have this docker compose node that
was created and this really has all of
the assets to build and configure your
containers when you actually run it okay
so you have this docker compose file
here and this is really just saying get
that image that eShop legacy embassy
image and it uses that docker file that
I just showed you for context ok and you
also have an override file and this is
just defining some additional
environmental variables to help it run
so it's for example exposing important
so the cool thing you know studio is it
wraps all the plumbing for me you can do
this from the command prompt many many
people do yeah or you can right-click
and have Visual Studio do it for you
yeah and the other cool thing is these
are all text files yeah so instead of
having to install a bunch of things on
your VM you can just go and make some
changes in these text files and it's
pretty easy to add dependencies add new
things or configure how you need to
which is very cool and you haven't
touched the app nope haven't touched the
apps app is exactly the same all I did
was add docker support mhm
so now if I start up with adding docker
oops I wanted to start without debugging
so you can debug into your container if
you need to but for a faster startup I
just started without debugging here and
you can see down here it's getting these
images it's making sure all the
containers are ready and it'll start up
the same web app now at an IP address
so this is the IP address of the
container itself and if that's something
that you want to find out later you can
even go to your command prompt say and
say first you'd have to find out what
the name of the container is right so
docker PS is a good way to do that so
that'll give you all the containers that
are currently running on your machine so
once you have that container ID you can
say docker inspect and this is going to
give you all that information about the
container including what that IP address
is if you now have this app running in a
docker container locally on your Windows
10 machine correct exactly cool and it's
running at this IP as you can see it's
the same exact catalog as I showed
before yep talking to sequel server not
yet not yet
for this one we didn't implement so if
you see the docker PS only brings up
your one container for this each shop
legacy MVC but if this app was talking
to a sequel server then the container
can talk to that machine - exactly it's
essentially when it's equivalent of a
Windows machine running on your network
yep right exactly and we'll show that in
the next examples you don't have to do
anything with the sequel server no no
it'll be in its own container
it'll just a Janee in a container though
you could contain it you can't leave it
where it is you could okay exactly it
could be either way right okay cool
easy yeah and then another thing you can
do is type docker images and this is
going to show you that you have that
image on your machine so we have that
asp.net core image right here mhm and we
also have that you shop like a CNBC ok
right which is so the the basic image is
peanut running on core seven and a half
gigs this asp net one is today they take
a bit of space they do take a windows
can
sandurz take a bit of space of you yeah
are sitting there with like 12 gig left
on your hard drive then you're gonna
have a hard time yeah running on that
machine if you wanted to delete these
images those you could also do that and
you wouldn't affect things on your
mission so there's also a way to there's
a dr. command to take the image and put
it in a tar file but you could then move
to a different computer wipe all the
images off if you needed the disk space
great we're just playing around with it
and then take the tar file and rehydrate
it as images I discovered that when a
while ago yeah pretty cool that's a good
one too huh yeah I have quite a few
images on here just because I play
around with this a lot but yeah I'll
probably have to clean them out at some
point cool so let's get into the second
scenario which is a little bit more
complex but pretty similar so in this
one so you have a three-tier scenario
and for for this you have a WinForms
front end you have a WCF middle tier and
a sequel server back-end okay so this
might be a little bit more traditional
three-tier and to your app that you
might have in your mind of business
application so this is based on the same
a shop example again we go back to
visual studio I have this up and running
just so we can show you and in four
seven one you at the high DPI support
isn't at all it doesn't get all crazy
yes so this isn't a high DPI monitor
itself okay which is why it looks a
little funky here but what if you had a
high if you had a hundred would
automatically adjust exactly so we can
do the same thing here and right click
on this WCF service and say add docker
support
and again it's going to auto-generate
some files here but we're gonna have to
make some modifications this time and
that's because this is only generating
files just for the WCF service since
that's what I right clicked on and not a
docker support for it so now I want to
put that sequel server in a container -
okay and say ok now we have two
containers and I want to make the
service actually talk to the e sequel
server ok so if you're gonna leave it
that the WCF service talks to the same
sequel server mm-hmm
sitting somewhere else then you wouldn't
need to yeah additional changes right
there's a few changes in this base file
that you need to make which is
documented on the site yeah what WCF
services does this have does it have all
of them right no WS transport WS this
that the other thing exactly you might
need to add some additional things yep
so first we're gonna add those
additional things just for the WCF
portion and
all we're doing here is adding some
additional things to make the
environment full and this is all
documented online and something you have
to do when you advertising port 83
that's what that is
and then if we go to the compose file
here's where we're going to add the
dependency on the sequel server so we
will take this
and this now depends on sequel data and
this year is referring to the sequel
server image so now it's gonna pull both
that WCF image and the sequel image onto
your machine so again the first time you
run this it's gonna take quite a bit of
time because you have to pull both of
these images and on that container
you've got sequel server but you'd have
to put your database on and then setup
your users and your security the same
way you do any sequel server because
again that's it is a sequel server
exactly yeah
the last step is to actually put that
connection string info and your override
files cool yes so I thought you know a
lot sequel management's do you know
actually I can just put in the text so I
have my connection string I have my
password here I have all the credentials
here and I'm talking to that port 83
that I exposed okay and that's really
just these in additional environmental
variables right here and that's actually
it so even to add support and dependency
for the sequel server container there
was a little bit of work but it wasn't
we architected my code didn't go into my
app and change it at all now it's
running and now it's all set up to run
in docker
okay so let's start
docker and this one will take a little
bit more time just based on the fact
that you have these two containers that
need to start up so you started without
the debugging which is faster but if you
start with the debugging then you
actually can set the breakpoints and
debug the app all that's running it yes
yeah you can do that as well if that's
something that you need to look into
right
I mean presumably the apps been tested
locally and works just fine but
hopefully you never know it's always
useful to have that option right exactly
and so you can see here we've created
it's creating this equal container now
and now it's moving on to the WCF
container you can see in the output here
so if I go back here and I type in
docker yes you'll see that I have I
still have that container from before
because I didn't do anything with it but
now I have this new sequel container and
when the WCF container is done that will
show up here as well now in the WinForms
app you need to point it to see to the
WCF service running somewhere else no so
that I didn't have to make any changes
to the one for his front end so the wind
farms was already talking to the WCF
service just locally and you just had to
containerize the WCF service and it can
still talk isn't it running on a
different yeah oh yes yes okay that's
what you're saying yeah yes exactly
point in the web not the app config
current is to a different server yes
exactly so again the I P address right
exactly so now we have this starting up
here and we have the service so this is
the service itself and exactly we're
going to take this IP address and we're
going to put this into the app config
file here
and so right now it had the endpoint as
localhost that's what we were talking to
you before so this is what you'll
replace with the IP address and do you
get to assign names or do you always
have to use IP address I have to use IP
address unfortunately I don't know if
there's a way to do it with the ID of
the container or not I haven't looked
into that at all but IP is definitely
the easiest way to go so now if we start
yep it's so sterile not impersonal it's
true you can't name your container
something something interesting so now
I've started up an instance of the
WinForms front-end again and that's
going to be talking to the IP address
I'll take a few seconds
you
this is so cool because you didn't have
to change any of the app you just had to
basically change the where the sir the
pointer to the sir exactly and you
Visual Studio menu obviously you need to
you need to learn more about docker
right but that's it's not that hard to
learn how to yeah yeah exactly
where the image is what does it mean how
do you start and stop a container you
this is really good documentation on the
docker site there's you know inexpensive
books you can get but you've taken this
application and containerized it in 20
well we talked to 16 minutes right yeah
not counting the time it takes to
download the images right yeah so that
would take a little bit more time sure
listen now so a question I have we
talked about some of the benefits of
containers there's to modernize to cloud
enable these things you could have taken
that NBC app and published it to an
azure web app you could take this WCF
service and publish it to an azure web
app so talk about when you might do one
versus the other yeah I think there's a
couple of key points so the first is
about deployment so as we were talking
about before you don't know what
framework version this is running in and
so you publish this to app service and
this is running in the latest framework
version but app service doesn't yet
support the latest done at framework
version so sometimes a gap there okay so
with containers that's not an issue
because your frameworks gonna come with
your container and all those
dependencies are kind of baked in in
addition to framework it could be
another third-party dependency so a lot
of existing line of business
applications have things like complex
components or other dependencies and so
all of those dependencies are really
packaged in for you and you don't have
to worry about installing them
separately or worrying about them the
second is really to improve DevOps and
improve dev test environments so you can
start up a test environment really
easily like
talked about before so you can set up
your dev test environment using the
container you don't in this case you
don't have to even install sequel server
on your right because you have it in the
container the containers gonna come down
to your machine and that's much easier
than say installing all of that from the
ground up yeah
so should really help if this app was
using sequel server 2010 for example and
we weren't going to touch it but I've
got 2017 on my machine exactly and in
addition you could test it into your dev
your test environment and you could be a
lot more certain that it's actually
gonna work in production so I think
those are kind of the key things I would
point out I guess also you can run
containers locally you don't need a
server just fine so yep you can run them
locally you can deploy them to the cloud
if you want to right we obviously when
we DS when we talk about containers were
typically you know deploying them into
Azure you know for a couple reasons one
because we also want to talk about Azure
none of us are lugging around Windows
Server machine so it's just a heck of a
lot easier to put it in a jar right
exactly yeah that's actually what we can
talk about the next time okay that we
chat so I think in the next session we
can talk a little bit more about okay
now we have them running in containers
locally but right how do we get this to
the cloud what are all the different
ways you can get there how do you scale
out your application we can talk about
orchestrators okay which you may have
talked about in your microservices
episode as well a little bit yeah yeah
so I think those are kind of the next
steps in this scenario yeah but this is
really the basics and the first part of
getting towards they're cool so this is
a good stopping point and we will pick
this up again and the next one see you
next time on visual studio toolbox bye
picture
[Music]

No comments:

Post a Comment