It’s time for another video! This time, join me as I walk through Creating a SQL Server docker container using VS Code. As a bonus, I’ll also show you how to create a PostgreSQL server in a docker container.
Hope you find this helpful and let me know your thoughts!
I do have some links at the end as reference. They are:
- https://learn.microsoft.com/en-us/sql/tools/visual-studio-code-extensions/mssql/mssql-extension-visual-studio-code?view=sql-server-ver17
- https://docs.docker.com/engine/install/
- https://debthedba.wordpress.com/2020/09/04/installing-docker/
- https://debthedba.wordpress.com/2020/09/30/docker-sql-server-and-ports/
As an added bonus, I’m including my transcript below along with tips about where I am in the video. I know some people prefer to read than watch so hopefully a combination of the two will make it easier to see if the video has the info you’re looking for and where to find it. If you find this useful, let me know!
Hi everyone! My name is Deborah Melkin. I’m Deb the DBA. That’s my blog. That’s my YouTube channel, and that’s my GitHub. I’m a Microsoft MVP for the Data Platform. I wanted to take a moment and talk about creating a SQL Server Docker container from VS Code, from Visual Studio Code. I know that’s not a lot of words we usually put together in the Data Platform, but it’s a really useful thing to have. For those of you who don’t know what a container is, it’s essentially a virtualized instance of an application. Or at least that’s how I’d like to think about it. It makes a lot more sense. We know virtual machines, which is essentially a virtualization of an entire server. A container is a smaller portion of that. It’s just the application. It just has what we need to run an instance of SQL Server. So we don’t have to worry about multiple instances of SQL Server on our local machine, for example, or maybe we just need something temporarily. So we can create a Docker container for just that
version and then get rid of it once we don’t need it anymore. It’s a really quick and easy way to spin up a SQL Server so we can do whatever sort of testing we need and then move on.
Now they’ve made some changes in improvements and the Microsoft SQL Server extension as part of VS Code. And this is one of those hidden little things where if you don’t know to look, you may miss it, but it’s really useful. So I thought we take a moment and take a look. Alright, let’s jump over to VS Code.
(video: 00:01:39)
Here we are in VS Code. The first thing I’m going to to do is go to my SQL Server extension. I have it on the sidebar here, SQL Server, clicking that. I don’t have any connections set up, but that’s all right. What we’re going to do is we’re going to create a local SQL container right here. There’s also an icon for this above here. All I do is I click and now we have the welcome page for creating a local SQL Server database container.
Great, we have information here if interested. I’m going to go ahead and choose get started. First thing it does as it goes through the prerequisites. Starting with, do you have Docker installed? If you don’t, all you have to do is click the link. It will take you to the pages so you can then install it. I don’t have it here yet. So let
me go install it and I’ll be right back.
(video: 00:02:29)
All right, I’ve installed Docker. I’m all set up. So now we’re back in VS code starting over. I’m going to create my local SQL container. I’m going to say get started. It goes through the check. Everything is up and running. We’re ready to go next.
(video: 00:02:43)
The first thing we do is select the version of SQL Server we want. We have everything from 2017 to 2025. Notice we’re only being given the latest version. So if you need to do something more specific, let’s say you do need a specific CU install for whatever test you’re doing. This may not be the right one thing to use. We’re talking about getting a quick start for containers. So I’m just going to choose SQL Server 2025
latest. I’m going to create a password and I’m going to save it because when it’s done, it’s going to have that connection saved for me. I’m going to create a profile name, demo test. I’m going to leave the connection group alone for now. Advanced options, I always like specifying a container name.
Port. My default SQL Server port is 1433. For my containers, I like to specify a port. Part of the reason is if I had a local instance installed, my port is 1433. If I were to leave that port here and choose the default 1433, there may be cases where I’m not necessarily connecting to the correct instance. I have a blog post about this that I did several years ago. You’ll find that in the resources. So for now, I’m going to choose 2025. For some reason, I like coordinating the ports with the version of SQL Server I’m using. We’re just going to go with that for now. And I’m going to go ahead and specify a host name. I like keeping those the same. The last thing that I do is I accept my terms and conditions.
And then I’m going to create my container. If you haven’t pulled your SQL Server image, it may take a couple minutes for that you to do that. But now we can see as creating container, it’s now setting everything up.
And just a few moments, we’ll be able to connect to our container. And we’re done. I’m clicking finish. And we can see our connections over here, DemoTest. It’s actually kind of cool if you look. Let’s see if I can zoom in. Oh look, it’s the icon for a Docker container. So we could even see right here that this is a container. And now I can connect. And I can get started with my SQL Server pretty much like any other. And now I’m often running.
(video: 00:05:04)
Now that we have our SQL Server Docker containers up and running, we want to be able to manage to. Now, we can do that through Docker desktop or PowerShell or other tools that are available to us. But we can also do that through VS code through extensions.
I’m going to go through my extensions. And I’m going to look up “Docker”. And I have the extension here. I’m going to go ahead and install this. And we should be able to add at this to our sidebar: “Containers”. And now I can do management of our containers from here. We can see I have the SQL Server 2025 latest.
This is the container we just created. We can see the image that it’s using. If we had a lot more Docker containers set up and more intricate connections, and volumes. And that’s sort of thing. We would be able to see those here. But we just created the very basic Docker container. But we can see that from here. So if we wanted to, we could stop this. We could start it if it was stopped. So we can do some basic container management right from VS code.
(video: 00:06:12)
Now, I don’t know about you. But I find there’s a lot of pressure these days to be multiple database platform. Our data is a multiple different places; everyone’s using different things for it. So we need to be able to go from one to another. And as a SQL server DBA, I don’t know about you, but PostgreSQL is the one that I’m constantly hearing about.
So we’re talking about creating Docker containers for SQL Server, can I do it for Postgres? Well, let’s take a look.
(video: 00:06:44 )
There happens to be an extension of VS code for post-cress from Microsoft. And I’ve already set that up. So let me click here. I don’t have Postgres installed. So now I
need to create a server. And there’s an icon for that. Create a new server.
One of these options isn’t available yet, but I’m really curious about that. Create an Azure database for Postgres. That’s kind of cool. But we’re talking about Docker containers today. So let’s go do that.
Let’s see what happens here. Create my local create local Docker Postgres server. Okay, I’m going to choose get started. First thing it does is make sure that Docker is installed up and running, which it is. Going to hit continue. So let’s create a name: LearnPostgres. And that’s going to be my container name. I’m going to keep the username and use the default. Create a password. Save that so it’ll connect. Choose the default database name and server group. There are some advanced options. But for now, I’m just going to go ahead and take the default. So I’m choosing create.
Just a couple clicks of the button will wait for everything to get set up. And there we are. Here’s my server and my databases are here. So that was pretty quick. I can now be learning Postgres. I’m off and running. Maybe don’t tell my manager how easy that is, huh?
(video: 00:08:15)
There you have it. With a couple clicks of the button, we were able to set up our databases in Docker container. Pretty easy. Now, if we need something a little more complicated, this may not be the best method. But if we need a quick start, this
is a great way to get started.
I’m leaving you with a couple resources that I like doing that in case you have any other question. I’ve included a couple blog posts that I had written a one about installing Docker and the other is about SQL Server port numbers. As I mentioned earlier, you want to be really careful if you have things like named instances or multiple Docker containers running that are all using that default 1433 port. It’s
a little gotcha if you didn’t know you needed to look at for it.
I hope you found this useful. If so, leave a comment, let me know. And with that, have fun and I’ll talk to you next time!
Thanks Deb! Getting started videos like this are very helpful!
LikeLike