Okay, we've been running on SQLite all the way through so far and SQLite is great.
Makes our application very portable as we can simply clone our project and instantly get our database
up and running, even if we don't have a database server installed or available on our operating system.
But SQLite, as good as it is for development or can be good for development, it's no good for production
because its limitations are significant, and we want to move on to a production worthy database server
that we can then test in development to make sure our application still functions correctly.
And then, of course, for deployment, we can then deploy our application and use a production worthy
database server.
Now the server that we're going to utilize, because the plan is to deploy our application to Azure
is to use SQL server.
Now if you're on windows you have two options.
Really, you can install SQL server onto your operating system and then run it locally on your developer
machine.
And you can download this from Microsoft.
And there's a developer edition that doesn't cost anything that you can use to run and test locally
in a non-production environment.
Perfect for that.
However, this is only for windows.
It's not for Macs.
If we want to use it on Linux or Apple and Windows, then we can use a Docker container to do so.
And this is the approach that we use when not on windows.
So you have a choice.
Docker is by far and away the easiest, most convenient way to run anything like this on our operating
systems nowadays.
So I would suggest using Docker.
And if we go to Docker.com, we can take a look at what we need for this.
And if we go to the products and take a look at Docker Desktop, this gives us Docker and a way to view
our running containers.
Now Docker is a type of virtualization where it runs applications inside containers, and it operates
above the operating system level.
So it doesn't matter which operating system we're on, the container will be the same across different
OSes.
And this is the approach I will be demonstrating to run SQL server.
Now we don't need to create an account or anything with Docker.
It's completely free to use.
So if you are on windows, what I'd recommend just go to developers and the Getting Started documentation.
And this should give us a link to learn how to install Docker.
And I point this out because if you're on windows, there's a few things you may need to enable.
And depending on what computer you're using, maybe you even need to enable something inside your Bios.
Also, there's different types of features that are available on Windows Pro editions compared to Home
Edition.
So if you are going to use Docker on Windows, then I would recommend you take a look at the setup inside
here and running Docker Desktop for windows.
And where's the installation guide?
It must be inside this one.
So go to the install.
Go to windows and this will tell you how to go ahead and install this, what the system requirements
are, and also whether or not you're going to use the Windows Subsystem for Linux two back end.
Or if you're on Windows Pro Edition, then you've got access to Hyper-V.
If you're on Pro, you can use either option.
If you're on Home Edition, you have to use the SLT back end fully virtualization aspect of this.
And please make sure you meet their system requirements.
And also inside this you may need to do something inside your Bios as well.
So what I'm suggesting is if you do want to use Docker, then please take a look at the installation
requirements and follow it step by step for what you need to do to get this installed.
Once you do have this installed, then you can open up Docker Desktop and this will give you something
like this, and we can see what containers we're running inside here.
Now all we're going to use this for is simply to run SQL server.
I'm not going to use it for anything else.
And if you're on Mac, then there is a setting that you will need to check inside here as well, because
there used to be a version of SQL server.
Azure SQL edge, it was called that did run natively on the Apple silicon chips, but they have discontinued
that.
So now we have to use the full version of SQL server, which is fine, but we need to enable something
inside here.
So click on the settings and what you're looking for inside here is the virtual machine options.
And make sure you've got this enabled.
The Rosetta for x86 64 Amd64 emulation on Apple Silicon.
We do need that enabled in order to run SQL server.
So with that enabled and we have Docker installed and available, then we can effectively run a SQL
server.
If you're on windows and you're just installing SQL server natively on your machine, then just make
sure SQL server is up and running, as that's the point I'm going to get to in this lesson before configuring
it in the next lesson.
So inside VS code, let's go back to VS code.
And inside the file and folder explorer.
I'll just close the other stuff down for the time being.
And inside the folder explorer at the root of our solution we'll just create a new file.
And this needs to be called Docker compose dot y m l.
We use YAML files to configure Docker and we'll get a prompt from vs code.
Recognizing that we've created a Docker file, do we want to install the Docker extension?
It can be useful, but we don't really need it for the minimal amount of things that we're using Docker
for.
Inside our docker compose file we specify.
And I said it's not worth it, but it does give us intellisense as we're typing this Docker file.
So it may be beneficial to use the Docker extension here because it does provide benefits even for the
minimal amount we're using it for.
So I am going to go ahead and install it into VSCode.
And once this is available, if we now start typing inside our Docker compose file, notice that we
get some help from our editor.
So the first line inside here is the services.
What services do we want to run.
Well we want to run a SQL server.
We'll just give it a name of SQL and then go on to the next line.
Now inside a YAML file.
If you've not come across these before, these are the fussiest files in existence.
They don't have semicolons to terminate a line, and they use spacing to separate different parts of
our code.
So where I've got services here, if I have SQL in line with services, this will not work.
It has to be tabbed to the next tab inside this file, and we don't use semicolons or anything like
that.
It's really kind of fussy file.
So after SQL and colon we'll press return hit tab.
And then we can specify what image we wish to use.
This is the image that effectively we're going to download from Microsoft and use to run a SQL server
instance via Docker.
So I'm going to say MCR period microsoft.com forward slash Ms-sql forward slash server colon 2022 dash
latest.
And this is the SQL server image.
And then we can specify an environment and pass it key value pairs that we need inside here.
Now it's offered to give us a dash.
We don't need that dash.
So I'm going to remove that and make sure I'm underneath the environment Plus tab.
And then we need to accept the end user license agreement inside here.
So I'm going to say accept underscore EU le colon.
And then in quotes y.
And below this we'll have Ms. SQL underscore sa underscore password.
And I'm going to use.
And it does need to be a complex password.
But Docker is kind of fussy on what special characters it will accept inside here.
So what I would recommend is just do exactly what I'm about to do for the password.
And if you see it working on my machine, then the same thing will work on your machine.
If you do have issues authenticating with SQL server and you're using things like hashes and dollars
and it's not working, it's possible that Dockers converted them into something else without telling
you.
So I would suggest that you use something like this p a s s w o r d at one.
It does need to meet a certain level of complexity below the environment, so please make sure your
cursor is below environment.
Here we'll specify ports and Docker uses an internal and external port system.
So we'll use a dash here.
And then in quotes we say 1433 fully internal ports and also 1433 for the external port.
So we're just going to run SQL server on its default port which is 1433.
And then we can specify some storage where we're going to store the database effectively.
As we do have the ability to persist the data inside Docker.
So we'll use volumes, add a tab add a dash.
And we're going to call it SQL data colon.
And this specific path needs to be VAR forward slash forward slash Ms-sql as that's where SQL expects
to find its storage for where it's going to store the database.
Also, if you're on a mac and this part is Mac specific, we need to specify platform.
And in quotes we'll say Linux forward slash amd64.
You don't need to do this on windows only if you're using an ARM based system.
And then below the services.
So I'll tab or backspace to the beginning of the line.
Then we'll say volumes and we'll specify SQL data and colon.
That colon is important to you.
So your file needs to look exactly like this.
Unless you're on windows then platform you shouldn't need to use because I'm assuming that you're on
an Intel chip with windows, but that actually may not be the case nowadays.
So if you're running on an ARM chip of any description windows, Linux or Mac, then please make sure
you have the platform available there.
Hopefully one day Microsoft will release a version of SQL server that is compatible with ARM based chips
because their latest versions of windows computers are using that system now, so hopefully it won't
be too long before they do focus on releasing ARM versions of their software.
But that day is not today, so that's what we need to use.
So with this in place, what we should be able to do then is we can open up our terminal.
I'll go on to a spare tab where we have the client.
I don't need this fourth tab.
And we need to CD up into the location of where our Docker compose file is.
Then we can use docker compose up, and we'll specify dash d to run it in detached mode.
So we don't see all of the logs inside here and press return.
Now.
If we don't have this on our operating system already, then it's going to go and download the binaries
for SQL server.
And then once it has them then it's going to start SQL server.
So I'll pause the video and come back once this has started running.
Okay.
So that took a few minutes and it is now downloaded and it is up and running.
And if we head back to Docker Desktop then what we should see is inside our containers.
We now have a running instance of SQL server.
Because I'm on an Apple silicon chip, I see this image may have poor performance.
It won't have poor performance for what we're doing here.
It will work just fine.
And if we click on the SQL server, then we get taken to its logs and we can see that our SQL server
is indeed up and running.
So once it's running, we're then happy.
And then we can move on to the next step, which is hooking up our application to this running instance
of SQL server.
And we'll take a look at that next.