WEBVTT

00:00.020 --> 00:04.970
Okay, we've been running on SQLite all the way through so far and SQLite is great.

00:05.000 --> 00:12.200
Makes our application very portable as we can simply clone our project and instantly get our database

00:12.200 --> 00:18.020
up and running, even if we don't have a database server installed or available on our operating system.

00:18.020 --> 00:24.260
But SQLite, as good as it is for development or can be good for development, it's no good for production

00:24.260 --> 00:31.550
because its limitations are significant, and we want to move on to a production worthy database server

00:31.580 --> 00:36.710
that we can then test in development to make sure our application still functions correctly.

00:36.710 --> 00:42.650
And then, of course, for deployment, we can then deploy our application and use a production worthy

00:42.680 --> 00:43.550
database server.

00:43.580 --> 00:49.730
Now the server that we're going to utilize, because the plan is to deploy our application to Azure

00:49.760 --> 00:51.560
is to use SQL server.

00:51.590 --> 00:54.260
Now if you're on windows you have two options.

00:54.260 --> 01:00.940
Really, you can install SQL server onto your operating system and then run it locally on your developer

01:00.940 --> 01:01.690
machine.

01:01.720 --> 01:04.450
And you can download this from Microsoft.

01:04.450 --> 01:11.500
And there's a developer edition that doesn't cost anything that you can use to run and test locally

01:11.500 --> 01:13.570
in a non-production environment.

01:13.570 --> 01:14.710
Perfect for that.

01:14.740 --> 01:16.870
However, this is only for windows.

01:16.870 --> 01:19.540
It's not for Macs.

01:19.540 --> 01:27.610
If we want to use it on Linux or Apple and Windows, then we can use a Docker container to do so.

01:27.610 --> 01:32.320
And this is the approach that we use when not on windows.

01:32.320 --> 01:33.790
So you have a choice.

01:33.820 --> 01:40.150
Docker is by far and away the easiest, most convenient way to run anything like this on our operating

01:40.150 --> 01:40.990
systems nowadays.

01:40.990 --> 01:42.940
So I would suggest using Docker.

01:42.940 --> 01:46.630
And if we go to Docker.com, we can take a look at what we need for this.

01:46.630 --> 01:52.420
And if we go to the products and take a look at Docker Desktop, this gives us Docker and a way to view

01:52.450 --> 01:53.950
our running containers.

01:53.980 --> 02:02.680
Now Docker is a type of virtualization where it runs applications inside containers, and it operates

02:02.680 --> 02:04.510
above the operating system level.

02:04.510 --> 02:10.090
So it doesn't matter which operating system we're on, the container will be the same across different

02:10.120 --> 02:11.230
OSes.

02:11.260 --> 02:15.910
And this is the approach I will be demonstrating to run SQL server.

02:15.940 --> 02:18.610
Now we don't need to create an account or anything with Docker.

02:18.610 --> 02:20.170
It's completely free to use.

02:20.170 --> 02:27.070
So if you are on windows, what I'd recommend just go to developers and the Getting Started documentation.

02:27.070 --> 02:31.270
And this should give us a link to learn how to install Docker.

02:31.270 --> 02:36.520
And I point this out because if you're on windows, there's a few things you may need to enable.

02:36.520 --> 02:43.090
And depending on what computer you're using, maybe you even need to enable something inside your Bios.

02:43.120 --> 02:49.840
Also, there's different types of features that are available on Windows Pro editions compared to Home

02:49.840 --> 02:50.320
Edition.

02:50.320 --> 02:56.770
So if you are going to use Docker on Windows, then I would recommend you take a look at the setup inside

02:56.770 --> 03:01.380
here and running Docker Desktop for windows.

03:01.650 --> 03:04.410
And where's the installation guide?

03:04.410 --> 03:06.000
It must be inside this one.

03:06.000 --> 03:07.050
So go to the install.

03:07.080 --> 03:13.290
Go to windows and this will tell you how to go ahead and install this, what the system requirements

03:13.290 --> 03:18.960
are, and also whether or not you're going to use the Windows Subsystem for Linux two back end.

03:18.960 --> 03:23.490
Or if you're on Windows Pro Edition, then you've got access to Hyper-V.

03:23.610 --> 03:26.100
If you're on Pro, you can use either option.

03:26.670 --> 03:32.910
If you're on Home Edition, you have to use the SLT back end fully virtualization aspect of this.

03:32.910 --> 03:36.090
And please make sure you meet their system requirements.

03:36.090 --> 03:40.590
And also inside this you may need to do something inside your Bios as well.

03:40.590 --> 03:47.160
So what I'm suggesting is if you do want to use Docker, then please take a look at the installation

03:47.160 --> 03:52.920
requirements and follow it step by step for what you need to do to get this installed.

03:53.100 --> 04:00.210
Once you do have this installed, then you can open up Docker Desktop and this will give you something

04:00.270 --> 04:04.590
like this, and we can see what containers we're running inside here.

04:04.620 --> 04:08.550
Now all we're going to use this for is simply to run SQL server.

04:08.580 --> 04:10.800
I'm not going to use it for anything else.

04:10.800 --> 04:17.910
And if you're on Mac, then there is a setting that you will need to check inside here as well, because

04:17.910 --> 04:21.780
there used to be a version of SQL server.

04:21.810 --> 04:30.900
Azure SQL edge, it was called that did run natively on the Apple silicon chips, but they have discontinued

04:30.900 --> 04:31.170
that.

04:31.170 --> 04:38.130
So now we have to use the full version of SQL server, which is fine, but we need to enable something

04:38.130 --> 04:39.240
inside here.

04:39.240 --> 04:46.260
So click on the settings and what you're looking for inside here is the virtual machine options.

04:46.260 --> 04:48.840
And make sure you've got this enabled.

04:48.840 --> 04:56.130
The Rosetta for x86 64 Amd64 emulation on Apple Silicon.

04:56.130 --> 05:00.090
We do need that enabled in order to run SQL server.

05:00.110 --> 05:08.510
So with that enabled and we have Docker installed and available, then we can effectively run a SQL

05:08.510 --> 05:08.990
server.

05:08.990 --> 05:14.150
If you're on windows and you're just installing SQL server natively on your machine, then just make

05:14.180 --> 05:21.230
sure SQL server is up and running, as that's the point I'm going to get to in this lesson before configuring

05:21.230 --> 05:22.940
it in the next lesson.

05:22.940 --> 05:26.540
So inside VS code, let's go back to VS code.

05:26.810 --> 05:29.900
And inside the file and folder explorer.

05:29.930 --> 05:32.450
I'll just close the other stuff down for the time being.

05:32.450 --> 05:39.320
And inside the folder explorer at the root of our solution we'll just create a new file.

05:39.320 --> 05:45.200
And this needs to be called Docker compose dot y m l.

05:45.290 --> 05:51.380
We use YAML files to configure Docker and we'll get a prompt from vs code.

05:51.380 --> 05:55.760
Recognizing that we've created a Docker file, do we want to install the Docker extension?

05:55.760 --> 06:00.290
It can be useful, but we don't really need it for the minimal amount of things that we're using Docker

06:00.290 --> 06:01.060
for.

06:01.240 --> 06:04.870
Inside our docker compose file we specify.

06:05.080 --> 06:10.570
And I said it's not worth it, but it does give us intellisense as we're typing this Docker file.

06:10.570 --> 06:19.030
So it may be beneficial to use the Docker extension here because it does provide benefits even for the

06:19.030 --> 06:20.650
minimal amount we're using it for.

06:20.650 --> 06:24.400
So I am going to go ahead and install it into VSCode.

06:25.150 --> 06:31.090
And once this is available, if we now start typing inside our Docker compose file, notice that we

06:31.090 --> 06:33.490
get some help from our editor.

06:33.490 --> 06:35.980
So the first line inside here is the services.

06:35.980 --> 06:37.600
What services do we want to run.

06:37.600 --> 06:39.580
Well we want to run a SQL server.

06:39.610 --> 06:43.750
We'll just give it a name of SQL and then go on to the next line.

06:43.780 --> 06:45.700
Now inside a YAML file.

06:45.700 --> 06:49.570
If you've not come across these before, these are the fussiest files in existence.

06:49.570 --> 06:55.810
They don't have semicolons to terminate a line, and they use spacing to separate different parts of

06:55.810 --> 06:56.620
our code.

06:56.620 --> 07:02.620
So where I've got services here, if I have SQL in line with services, this will not work.

07:02.620 --> 07:09.970
It has to be tabbed to the next tab inside this file, and we don't use semicolons or anything like

07:09.970 --> 07:10.270
that.

07:10.300 --> 07:12.550
It's really kind of fussy file.

07:12.550 --> 07:17.260
So after SQL and colon we'll press return hit tab.

07:17.260 --> 07:20.290
And then we can specify what image we wish to use.

07:20.290 --> 07:26.680
This is the image that effectively we're going to download from Microsoft and use to run a SQL server

07:26.680 --> 07:28.480
instance via Docker.

07:28.600 --> 07:42.310
So I'm going to say MCR period microsoft.com forward slash Ms-sql forward slash server colon 2022 dash

07:42.310 --> 07:43.390
latest.

07:43.870 --> 07:46.540
And this is the SQL server image.

07:46.540 --> 07:53.020
And then we can specify an environment and pass it key value pairs that we need inside here.

07:53.050 --> 07:54.730
Now it's offered to give us a dash.

07:54.730 --> 07:55.900
We don't need that dash.

07:55.900 --> 08:01.110
So I'm going to remove that and make sure I'm underneath the environment Plus tab.

08:01.110 --> 08:05.670
And then we need to accept the end user license agreement inside here.

08:05.670 --> 08:10.860
So I'm going to say accept underscore EU le colon.

08:11.070 --> 08:13.740
And then in quotes y.

08:14.280 --> 08:21.270
And below this we'll have Ms. SQL underscore sa underscore password.

08:21.720 --> 08:23.430
And I'm going to use.

08:23.460 --> 08:25.470
And it does need to be a complex password.

08:25.470 --> 08:31.560
But Docker is kind of fussy on what special characters it will accept inside here.

08:31.560 --> 08:36.840
So what I would recommend is just do exactly what I'm about to do for the password.

08:36.840 --> 08:41.520
And if you see it working on my machine, then the same thing will work on your machine.

08:41.520 --> 08:49.170
If you do have issues authenticating with SQL server and you're using things like hashes and dollars

08:49.170 --> 08:54.870
and it's not working, it's possible that Dockers converted them into something else without telling

08:54.870 --> 08:55.410
you.

08:55.410 --> 09:03.320
So I would suggest that you use something like this p a s s w o r d at one.

09:03.320 --> 09:09.770
It does need to meet a certain level of complexity below the environment, so please make sure your

09:09.770 --> 09:11.750
cursor is below environment.

09:11.780 --> 09:19.460
Here we'll specify ports and Docker uses an internal and external port system.

09:19.460 --> 09:21.680
So we'll use a dash here.

09:21.680 --> 09:30.440
And then in quotes we say 1433 fully internal ports and also 1433 for the external port.

09:31.100 --> 09:36.080
So we're just going to run SQL server on its default port which is 1433.

09:36.260 --> 09:41.930
And then we can specify some storage where we're going to store the database effectively.

09:42.230 --> 09:47.540
As we do have the ability to persist the data inside Docker.

09:47.780 --> 09:52.280
So we'll use volumes, add a tab add a dash.

09:52.310 --> 09:56.810
And we're going to call it SQL data colon.

09:56.810 --> 10:06.710
And this specific path needs to be VAR forward slash forward slash Ms-sql as that's where SQL expects

10:06.710 --> 10:11.000
to find its storage for where it's going to store the database.

10:11.030 --> 10:16.670
Also, if you're on a mac and this part is Mac specific, we need to specify platform.

10:16.670 --> 10:23.450
And in quotes we'll say Linux forward slash amd64.

10:23.480 --> 10:29.840
You don't need to do this on windows only if you're using an ARM based system.

10:30.050 --> 10:32.900
And then below the services.

10:33.320 --> 10:37.760
So I'll tab or backspace to the beginning of the line.

10:37.760 --> 10:44.930
Then we'll say volumes and we'll specify SQL data and colon.

10:44.960 --> 10:46.520
That colon is important to you.

10:46.550 --> 10:49.700
So your file needs to look exactly like this.

10:49.700 --> 10:55.100
Unless you're on windows then platform you shouldn't need to use because I'm assuming that you're on

10:55.100 --> 10:58.790
an Intel chip with windows, but that actually may not be the case nowadays.

10:58.790 --> 11:04.960
So if you're running on an ARM chip of any description windows, Linux or Mac, then please make sure

11:04.960 --> 11:07.810
you have the platform available there.

11:07.840 --> 11:15.250
Hopefully one day Microsoft will release a version of SQL server that is compatible with ARM based chips

11:15.250 --> 11:22.960
because their latest versions of windows computers are using that system now, so hopefully it won't

11:22.960 --> 11:28.390
be too long before they do focus on releasing ARM versions of their software.

11:28.390 --> 11:31.960
But that day is not today, so that's what we need to use.

11:31.960 --> 11:36.220
So with this in place, what we should be able to do then is we can open up our terminal.

11:36.250 --> 11:39.460
I'll go on to a spare tab where we have the client.

11:39.460 --> 11:40.810
I don't need this fourth tab.

11:40.810 --> 11:46.330
And we need to CD up into the location of where our Docker compose file is.

11:46.840 --> 11:55.750
Then we can use docker compose up, and we'll specify dash d to run it in detached mode.

11:55.750 --> 11:59.650
So we don't see all of the logs inside here and press return.

11:59.740 --> 12:00.220
Now.

12:00.220 --> 12:05.980
If we don't have this on our operating system already, then it's going to go and download the binaries

12:05.980 --> 12:07.150
for SQL server.

12:07.150 --> 12:10.780
And then once it has them then it's going to start SQL server.

12:10.780 --> 12:14.890
So I'll pause the video and come back once this has started running.

12:14.920 --> 12:15.340
Okay.

12:15.370 --> 12:20.170
So that took a few minutes and it is now downloaded and it is up and running.

12:20.170 --> 12:26.020
And if we head back to Docker Desktop then what we should see is inside our containers.

12:26.020 --> 12:29.500
We now have a running instance of SQL server.

12:29.800 --> 12:34.240
Because I'm on an Apple silicon chip, I see this image may have poor performance.

12:34.240 --> 12:36.790
It won't have poor performance for what we're doing here.

12:36.790 --> 12:39.190
It will work just fine.

12:39.190 --> 12:47.290
And if we click on the SQL server, then we get taken to its logs and we can see that our SQL server

12:47.290 --> 12:49.690
is indeed up and running.

12:49.720 --> 12:51.880
So once it's running, we're then happy.

12:51.880 --> 12:57.520
And then we can move on to the next step, which is hooking up our application to this running instance

12:57.520 --> 12:58.570
of SQL server.

12:58.570 --> 13:00.640
And we'll take a look at that next.
