I am having issues using the attach_dbs with docker-compose
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"
]
}
]


Am I supposed to have this configured differently ?
[@beaudryj] Does it work with docker run?
docker run -d -p 1433:1433 -v C:/temp/:C:/temp/ -e sa_password=
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?
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.
when I run the docker run it fails to find the files, I even modified the volumes to share my files in the volume
Do you have the C:\temp\sampledb.mdf and C:\temp\sampledb_log.ldf files on the host?
I used mine but yes
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

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:
- 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]
- 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
so it is not outputting anything now and when I do a docker ps there are no containers
- What environment are you using? Windows/Linux and what version
- What is the docker version that you have installed (docker version)

Thanks! Let me see if I can repro the same behavior on the same environment.
Just noticed on the os version thats running server 2016 not win 10
Are you on a Windows 10 or Windows Server 2016 host?
Windows Server 2016 Host
Did you follow the below article to setup? https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-windows-server
Yeah I did.

Let me setup a Win 2016 machine and get back to you.
👍 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