SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Changing the location of docker named volumes

A few weeks ago I was presenting at SQL Saturday Raleigh and was asked a question that I didn’t know the answer to.

The question was, “can you change the location of named volumes in docker?”

This is one of the things that I love about presenting, being asked questions that I don’t know the answer to. They give me something to go away and investigate (many thanks to Dave Walden (b|t) for his help!)

N.B. – I’ve previously written about persisting data using named volumes here

First let’s have a look at a named volume. To create one, run: –

docker volume create sqlserver

And now let’s have a look at it: –

docker volume inspect sqlserver

You can see above where the named volume lives on the host. But what if we want to change that location?

Well, in order to do so we need to use a docker volume plugin. Which unfortunately means that this functionality is not available on Windows or on MACs (as plugins aren’t supported on those platforms). The workaround is to run the plugin from a container but I would just mount a volume from the host (see here).

The plugin that I’m going to use is the Local Persist Plugin

Really simple to install: –

curl -fsSL https://raw.githubusercontent.com/CWSpear/local-persist/master/scripts/install.sh | sudo bash

And we are good to go!

Ok, let’s create a directory to point our named volume to: –

mkdir /sqlserver

And now we can create our named volume: –

docker volume create -d local-persist -o mountpoint=/sqlserver --name=sqlserver2

Let’s have a look at it: –

docker volume inspect sqlserver2

And there you have it, the named volume pointing to a custom location.

Thanks for reading!

The DBA Who Came In From The Cold

I’m Andrew Pruski and I am a SQL Server DBA with 5 years experience in database development and administration.

The online SQL Server community has helped me out immensely throughout my career, whether from providing reference material in blog posts, or answering my (sometimes obscure) questions on forums. So, to try and say thank you, I would like to contribute my own experiences in the hope that they could benefit someone out there.

So here’s my general ramblings and thoughts about working as a SQL Server DBA.

You can find me on twitter @DBAFromTheCold

If you have any feedback on my blog please send me an email to dbafromthecold@gmail.com.

Comments

Leave a comment on the original post [dbafromthecold.com, opens in a new window]

Loading comments...