Importing Data into a Linux Container
Published: May 08, 2024
I’ve specified Linux Container here although if you follow this then it’s also pretty easy to do the equivalent in a Windows Container. But I’m currently working through my Linux Container posts and therefore that’s what we’re sticking with.

So, the main point of this post is that we now have a Linux SQL Server up and running on our Windows Desktop but it’s of little to no use if it has no data for us to play with.

First things first, we need a bak file. Either make your own or go and download the AdventureWorks one from Microsoft (which is the one I’ll be using, albeit an older one). A quick Google will soon find that for you.

Next, we need to use a Docker command in order to create a directory within our Container in which we can place the bak file.

If you look back to my previous post (or are familiar with folder structures in Linux) you can see that we’re using "/var/opt/mssql/data" as our data drive. So let’s create a backup folder in a similar path:

docker exec -it SQL2019Linux mkdir /var/opt/mssql/backup


Remembering that my Container is named SQL2019Linux and so we’re going to execute something internally to our Container, that thing we’re executing is "mkdir" and which we know from DOS is "Make Directory" so we then list the path we’re creating.

We can now copy the bak file to the new directory. In my case I have the bak file in the D drive of my desktop:

docker cp "D:\SQL Server\Backups\AdventureWorks2012.bak" SQL2019Linux:/var/opt/mssql/backup


This is obvious enough, we’re just using CP to copy the file from a local folder to the Container’s folder.

So now we can Restore.

If you’ve never done this in Azure Data Studio then we Right Click our Server and select Manage:


This reveals a Task of Restore:


Click Restore and then fill in the appropriate information as requested (you can work this out):


Now hit “Restore” at the bottom in blue (not in my screenshot).


Once done we have our database to play with:




Easy as that.

Leave a Comment
Your email address will not be published. All fields are mandatory.
NB: Comments will only appear once they have been moderated.

Kutech  CEO
Kevin  Urquhart

CEO

I am a SQL Server DBA, Architect, Developer, Trainer, and the owner and CEO of Kutech. This blog has been going for nearly 10 years now over several guises and this is its new home. I hope you find it useful whatever your endeavour.

Categories


© Copyright 2021 Kutech Solutions Ltd.

Our site uses cookies only to personalise content and analyse traffic. We do not use cookies for advertising. Policy