From the course: Database Foundations: Intro to Databases

Database server containers

- [Narrator] The companies that create different relational database management systems often make official Docker images available for you to use. And from these, we'll build our own personal containers. You can think of an image as the blueprint or the model. An image is a software package that describes a default installation of the software and all of the components that it needs to run. From this blueprint or image, you'll build a container. The container will act like a fully encapsulated networked computer that's running the software described in the image. The neat thing about this arrangement is that you only need one copy of the image or one blueprint. And from that, you can build multiple containers that are all identical copies. Each one acts as its own virtual computer. You can have multiple containers running at the same time to create a virtual network, and you can delete containers and rebuild them whenever you want. The process starts with getting the image. You can find them by searching the Docker Hub. Right now, I'm viewing the Docker Hub page for Microsoft's SQL Server. This page describes the different images that are available for the SQL Server relational database management system, and it gives you some instructions on how to download and use them. Also on the Docker Hub is a similar page for PostgreSQL relational databases. Again, we have some information about the commands needed to download and use them on this page. So let's use all of this information to create a couple of containers for our own personal use. In the chapter two folder of the course exercise files is a file called Docker_Containers.txt. It has the commands that we need to run in a command prompt or a PowerShell window if you're on Windows or in your terminal application if you're on a Mac or Linux computer. So let's read through this document to see what it contains. There's two different sections. One here at the top for setting up a SQL Server instance. And down below, we have the commands for setting up a PostgreSQL instance. I have the links to the respective Docker Hub pages if you want those for easy reference. Then we have the specific Docker commands we need to run to set up the container. For SQL Server, there's two different commands depending on if you're on a PC or a Mac computer. And really the only difference is here we have double quotation marks that are used if you're on Windows or a single quotation mark if you're on macOS and Linux. Other than that small change, these two commands are identical. So let's read through the first one to see what it is. We'll start with docker run and then we'll name our new container. I'll name mine sqlserver2019. Then we need to accept the end user licensing agreement and you can read that licensing agreement back at the hub page if you'd like. Next up, we'll set up the password for the system administrator account. I'm using the password Adam123456. This needs to be a strong password with capital letters, lowercase letters and numbers and symbols, and it also needs to be more than eight characters in length. Now you can change this password to something else if you'd prefer. Just make sure that it matches those strong password requirements. If your password isn't strong enough, then the SQL Server container actually won't even start. After setting up the password, we're going to establish the communication ports that the container will use. SQL Server defaults to port 1433. So this is the port number that's going to be used inside of the container. The port that we use to communicate with the container can be something slightly different and in this case I'm going to use port 1401. I like using a slightly different port outside of the container from the port that's being used inside of the container so that it gives me some flexibility in setting up multiple different containers. So for instance, the first one I might use port 1401, the second one I would say 1402, and then 1403 for my third container. I'll just switch this back to 1401. After setting up the communication ports, we need to specify the image that we're going to use for the container, and that's the path that came from the Docker Hub. For SQL Server, that's mcr.microsoft.com/mssql/server. Now I'm going to use a specific version of SQL Server that's 2019-latest. SQL Server 2019 is not the most recent version of SQL Server. At the time that I'm recording this, SQL Server 2022 is available, but the 2019 version is stable and it's had most of the bugs worked out of it. So in the interest of providing a consistent experience for you so that what you see on your system matches what I'm doing, I want to make sure that we're all using the same version. And this will just help us avoid any incompatibilities or inconsistencies that may crop up when using software that's on the cutting edge of the release cycle. So this is the complete Docker command that'll set up our SQL Server container. We have a similar command for setting up PostgreSQL. Let me just scroll down here and we can take a look at that. It's docker run. We'll name the container postgresql. We'll set up the ports. Postgres by default uses port 5432, so that's the port inside of the container. And outside of the container, we'll communicate on port 5401. We also need to set up a password this time for the Postgres user account. And again, I'll use the same password, Adam123456. And finally, we'll need to use an image. It's simply postgres is the path and I'll specify the version of 14.8. So those are the commands that we need to run. Let's go ahead and set everything up. I'm going to scroll up here and I'll grab the command for the Windows PC to set up Microsoft SQL Server and I'll just copy that to my clipboard. Then I'll start up a command prompt. I'll just search for cmd to start up the command prompt application. Again, if you're on a Mac, you'll use the terminal application. I'll paste in that command there and press Enter. Now it tells me that it's unable to find the image which just means that it's not downloaded to my computer yet, so it needs to download it from the servers in order to install everything. Once that's done, I'll have a container running SQL Server up and running inside of Docker. All right, that's it for that. Let's go ahead and go back to that text file and I'll copy the command to set up my Postgres container. I'll just copy that to my clipboard. I'll return to the command prompt. I'll paste that one in and press Enter. Again, it can't find the Postgres image locally on my machine, so it needs to download it from the hub. Okay, that's complete. And now I have a Postgres database all set up. I can close the command prompt tool and I'll also close out of this text file and I don't need to save any changes to it. Now we can start up the Docker desktop application. This will allow us to manage the new containers that we just created. So here's the SQL Server container and there's the Postgres container. Over on the right, we have action options for stopping the container and restarting it. And we can also delete the container if we want to when we no longer want the databases that they contain. You can also perform these same management tasks on the terminal or the command line and I've made notes about the specific commands in the Docker_Containers.txt file if you want to see how those would work. So now I have two different database servers running inside of their isolated containers. As we learned earlier, the database server is just one part of the complete relational database management system. The next step is to connect using a client so that we can start telling the servers what we want them to do.

Contents