mssql-docker icon indicating copy to clipboard operation
mssql-docker copied to clipboard

I am having issues using the attach_dbs with docker-compose

Open beaudryj opened this issue 9 years ago • 34 comments

So I have a few issues with the attach_dbs when using it with docker-compose, I attempted building off of the example json which fails as invalid JSON so I cleaned it up.

[  
   {  
      "dbName":"MaxDb",
      "dbFiles":[  
         "C:\\temp\\maxtest.mdf",
         "C:\\temp\\maxtest_log.ldf"
      ]
   },
   {  
      "dbName":"PerryDb",
      "dbFiles":[  
         "C:\\temp\\perrytest.mdf",
         "C:\\temp\\perrytest_log.ldf"
      ]
   }
]

image

image

Am I supposed to have this configured differently ?

beaudryj avatar Mar 07 '17 22:03 beaudryj

[@beaudryj] Does it work with docker run? docker run -d -p 1433:1433 -v C:/temp/:C:/temp/ -e sa_password= -e ACCEPT_EULA=Y -e attach_dbs="[{'dbName':'SampleDB','dbFiles':['C:\temp\sampledb.mdf','C:\temp\sampledb_log. ldf']}]" microsoft/mssql-server-windows-express

perrysk-msft avatar Mar 07 '17 22:03 perrysk-msft

I'll try it out when I get home, but why should that matter if both methods are going to be grabbing an environment variable that is being set?

beaudryj avatar Mar 07 '17 22:03 beaudryj

It should not - I want to start by excluding everything else and see if the simple docker run with the attach_dbs var works on your side.

perrysk-msft avatar Mar 07 '17 22:03 perrysk-msft

when I run the docker run it fails to find the files, I even modified the volumes to share my files in the volume

beaudryj avatar Mar 07 '17 23:03 beaudryj

Do you have the C:\temp\sampledb.mdf and C:\temp\sampledb_log.ldf files on the host?

perrysk-msft avatar Mar 07 '17 23:03 perrysk-msft

I used mine but yes

beaudryj avatar Mar 07 '17 23:03 beaudryj

Could you please try the following when you can? I just noticed that the "\\" have been replaced by "\" in the earlier docker run that I posted:

docker run -d -p 1433:1433 -v C:/temp/:C:/temp/ -e sa_password= -e ACCEPT_EULA=Y -e attach_dbs="[{'dbName':'SampleDB','dbFiles':['C:\\temp\\sampledb.mdf','C:\\temp\\sampledb_log. ldf']}]" microsoft/mssql-server-windows-express

perrysk-msft avatar Mar 07 '17 23:03 perrysk-msft

image

beaudryj avatar Mar 08 '17 16:03 beaudryj

I was able to repro this behavior locally. By doing the following I was able to successfully run and connect to the container bypassing the error:

  1. Assign an sa_password (E.g. -e sa_password=Password1!) instead of leaving it blank. [Sorry about that, I should have put a sample password (E.g. sa_password=<YourStrongPassword!>) in the docker run command above]
  2. Passing the -a STDOUT before the name of the image

Could you please try the following and see if it works on your end (passing and sa_password and changing the position of the -a ): docker run -p 1433:1433 -v C:/temp/:C:/temp/ -e sa_password=Password1! -e ACCEPT_EULA=Y -e attach_dbs="[{'dbName':'SampleDB','dbFiles':['C:\temp\sampledb.mdf','C:\temp\sampledb_log. ldf']}]" -a STDOUT microsoft/mssql-server-windows-express

perrysk-msft avatar Mar 08 '17 18:03 perrysk-msft

so it is not outputting anything now and when I do a docker ps there are no containers

beaudryj avatar Mar 08 '17 19:03 beaudryj

  • What environment are you using? Windows/Linux and what version
  • What is the docker version that you have installed (docker version)

perrysk-msft avatar Mar 08 '17 19:03 perrysk-msft

image

beaudryj avatar Mar 08 '17 19:03 beaudryj

Thanks! Let me see if I can repro the same behavior on the same environment.

perrysk-msft avatar Mar 08 '17 19:03 perrysk-msft

Just noticed on the os version thats running server 2016 not win 10

beaudryj avatar Mar 08 '17 19:03 beaudryj

Are you on a Windows 10 or Windows Server 2016 host?

perrysk-msft avatar Mar 08 '17 19:03 perrysk-msft

Windows Server 2016 Host

beaudryj avatar Mar 08 '17 19:03 beaudryj

Did you follow the below article to setup? https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-windows-server

perrysk-msft avatar Mar 08 '17 19:03 perrysk-msft

Yeah I did.

image

beaudryj avatar Mar 08 '17 19:03 beaudryj

Let me setup a Win 2016 machine and get back to you.

perrysk-msft avatar Mar 08 '17 19:03 perrysk-msft

👍 thank you for the quick replys, in the mean time I pulled down the dockerfile and force set the variables. I wonder if it would be possible to refactor this in a way to have the script convert the yml down to JSON for people using docker compose.

ex:

services:
  db:
    image: microsoft/mssql-server-windows-express
    environment:
      sa_password: "Password1"
      ACCEPT_EULA: "Y"
      attach_dbs: 
        dbname: sampledb
        dbfiles: '["C:\\temp\\sample.mdf","C:\\temp\\sample_log.ldf"]'
    ports:
      - "1433:1433" # REMARK: This is currently required, needs investigation

beaudryj avatar Mar 08 '17 19:03 beaudryj