In my last post I showed how you can create a volume with your container. I then showed a few things you can with a container using a volume. I want to explore volumes just a little bit more.
Locate Your Volume
To have a little more fun with volumes, first, let’s share a drive. You do this in the Settings in Docker Desktop (assuming that’s what you’re using):
While this should just work, it didn’t for me until I restarted Docker. So you may need to do that. Go to the drive and create a directory. I’m putting one in at C:\Docker\SQL.
Once I’ve done that, let’s create a new container:
docker run `
--name SQL19 `
-p 1433:1433 `
-e "ACCEPT_EULA=Y" `
-e 'SA_PASSWORD=$cthulhu1988' `
-v C:\Docker\SQL:/sql `
Note, I’m using C:\Docker\SQL in the -v volume command and I’m telling it to map to /sql in my container.
Now, things get really fun. I’m going to add another folder: C:\Docker\sql\bu. In that folder, I’m going to add a file: AdventureWorks2017.bak.
Let’s connect up to our container directly. Use this command:
docker exec -it SQL19 "bash"
That will launch a bash shell inside the Linux container. There, I can list the files using the ‘ls’ command and it looks like this:
Notice the sql folder listed there. I can cd to that and I’ll see the bu folder. Changing to that directory and calling for a list, I’ll see my AdventureWorks2017.bak file.
Yes, I moved a file into a container by just copying it there. Yes, I could then run a restore from that backup.
Easily adding and controlling files this way adds to what we can do with containers. These things are going to become a major part of all my development and testing going forward. I’ll still be using VMs and all the rest of the stuff I have available. This is just another tool in the toolbox.
Please don’t miss out on my upcoming precons on DevOps and Query Tuning:
SQLSaturday Columbus Precon, June 7 2019, Columbus OH
SQLSaturday Indianapolis Precon, Friday August 16th, 2019. Click here now to register.
SQLSaturday Oslos Precon, Friday August 30th, 2019. Click here to register.