mikelus
mikelus

Reputation: 1039

How to create data volume in Docker for Windows 10 when using Windows Containers (as opposed to Linux Containers)

Folks, My OS is Windows 10 and I am running Docker version 17.06.0-ce-win19. I have SQL Server express running in a Windows container and I want to persist SQL data within a data volume that I would like to be located in my host file system. I don't know how to go about creating this data volume and associating it with my container.

Any examples I have seen are using Linux containers and "Shared Drive" properties under Docker/Settings. There are no "Shared Drive" settings when you are running a Windows Container (Hyper-V).

Upvotes: 4

Views: 4551

Answers (1)

mikelus
mikelus

Reputation: 1039

Create a volume, say data1 using the command: docker volume create data1

a folder will be created in the host at the location C:\ProgramData\Docker\volumes\data1

Now if you were going to spin up a sql server express container and wanted to store your data in this volume "data1" you would do something like:

docker run -d -p 1433:1433 -e sa_password=Nv7EtbMh8qLRM9s2 -v C:/ProgramData/Docker/volumes/data1:C:/data1 -e ACCEPT_EULA=Y --isolation=hyperv microsoft/mssql-server-windows-express

where -v C:/ProgramData/Docker/volumes/data1:C:/data1 is mapping your data1 volume at C:/ProgramData/Docker/volumes/data1 to a new folder within your container at c:/data1

Now when you create data files inside your container in c:/data1 they will persist to the host OS folder C:/ProgramData/Docker/volumes/data1

Upvotes: 4

Related Questions