microsoft / mssql-docker

Official Microsoft repository for SQL Server in Docker resources
MIT License
1.72k stars 758 forks source link

How to use volume for docker windows for existing databases #692

Closed ReadyToFlyAway closed 3 years ago

ReadyToFlyAway commented 3 years ago

Hello, I am new to docker and what I try to do is next: I am using docker window and my images is microsoft/mssql-server-windows-express. I have a web application in .net and this web is connected to an existing databases. I have more than 12 databases and I need to attach some of databases and some of them can be mount to the docker(if I understand mount correctly). I was able to copy and attach one database into docker. But when I try to mount my second database into docker I got error. My database is on path C:\MSSQLSERVER My attached database name is dbTranslations. My database that I want to mount to docker is dbTemp

I also can see that docker creates a default database on C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\DATA and my attached database is success fully copied and attached there. So logically I think I need to mount my temp database into docker path C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\DATA I have 2 dockerfiles one for web and one for sql. Can you please help me to understand what I am doing wrong.

Below are my docker-compose file and docker file for sql. my Dockerfile is like this

FROM microsoft/mssql-server-windows-express

copy the database files from host to container

ARG target="C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\DATA" ARG dgData3="dbTranslations.mdf" ARG dgData4="dbTranslations_log.ldf" COPY ${dgData3} ${target} COPY ${dgData4} ${target}

and my Docker-compose file

version: '3.4'

services: sqlsrv1: image: sqlsrvtest build: context: . dockerfile: .\Dockerfile environment:

i get next error, it seems that i can not give a path with space ERROR: for sqlsrv1 Cannot create container for service sqlsrv1: invalid volume specification: 'C:\MSSQLSERVER\dbTemp:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\DATA:rw'ERROR: Encountered errors while bringing up the project.

Any help is highly appreciated!

ReadyToFlyAway commented 3 years ago

I got it, Volumes work the same as copying a database to the docker, and the same we can attach them to the SQL server image on the docker. In the below example, I have 2 locally copied databases and one volume database, and I attach them as you can see...

version: '3.4'

services: sqlsrv1: image: sqlsrvdgoffice build: context: . dockerfile: .\Dockerfile environment: