My docker-compose needs to start three different containers: 1 MS SQL and three web applications. This is my docker-compose.yml:
version: "3"
services:
gwammssql:
image: microsoft/mssql-server-windows-express
container_name: mssql-gwam
networks:
- gwam_net
ports:
- "1433:1433"
environment:
- sa_password=Password01
- ACCEPT_EULA=Y
- attach_dbs="[{'dbName':'GWAM','dbFiles':['C:\\temp\\GWAM.mdf','C:\\temp\\GWAM.ldf']}]"
volumes:
- C:/temp/:C:/temp/
gwam-app:
image: myrepo/web-app
container_name: gwamapp1
ports:
- 6001:6001
depends_on:
- gwammssql
environment:
- ASPNETCORE_URLS=http://*:6001
- App__DatabaseInfo__ConnectionString=Data Source=gwammssql;Initial Catalog='GWAM';User ID='sa';Password='Password01';Connect Timeout=30;Pooling=false;
- App__DatabaseInfo__SelectTopValue=15
- App__SecretsKeys__TokenHashingKey=iraiadsafAiDailgattaBaL
- App__ExternalServices__MQServerUrl=localhost
- App__ExternalServices__MQUserName=guest
- App__ExternalServices__MQPassword=guest
- App__ExternalServices__MQPort=5672
networks:
- gwam_net
gwam-login:
image: myrepo/micro-login
container_name: gwamlogin1
ports:
- 6002:6002
depends_on:
- gwammssql
environment:
- ASPNETCORE_URLS=http://*:6002
- App__DatabaseInfo__ConnectionString=Data Source=gwammssql;Initial Catalog='GWAM';User ID='sa';Password='Password01';Connect Timeout=30;Pooling=false;
- App__DatabaseInfo__SelectTopValue=15
- App__SecretsKeys__TokenHashingKey=iraihgnAiDailgattaBaL
- App__ExternalServices__MQServerUrl=localhost
- App__ExternalServices__MQUserName=guest
- App__ExternalServices__MQPassword=guest
- App__ExternalServices__MQPort=5672
networks:
- gwam_net
gwam-account:
image: myrepo/micro-account
container_name: gwamaccount1
ports:
- 6003:6003
depends_on:
- gwammssql
environment:
- ASPNETCORE_URLS=http://*:6003
- App__DatabaseInfo__ConnectionString=Data Source=gwammssql;Initial Catalog='GWAM';User ID='sa';Password='Password01';Connect Timeout=30;Pooling=false;
- App__DatabaseInfo__SelectTopValue=15
- App__SecretsKeys__TokenHashingKey=iradgnAgilgattaBaL
- App__ExternalServices__MQServerUrl=localhost
- App__ExternalServices__MQUserName=guest
- App__ExternalServices__MQPassword=guest
- App__ExternalServices__MQPort=5672
networks:
- gwam_net
networks:
gwam_net:
external:
name: nat
The problem is the attach_dbs environment variable. I need to attach an .mdf and ldf file, but everytime I run the compose file I keep receiving the same output and the DB is not attached...

I hope you solved your problem, but just in case anyone else hits this thread. I had the same or at least a very similar issue. I'm running Windows containers on Windows 10 Enterprise.
This worked:
docker run --rm --name mssql -d -p 1433:1433 -e sa_password=myPassword -v ./data:C:/db/ -e ACCEPT_EULA=Y -e attach_dbs="[{'dbName':'myDB','dbFiles': ['c:\\db\\DB_Data.MDF', 'c:\\db\\DB_Log.LDF']}]" microsoft/mssql-server-windows-developer
But within my docker-compose it did not, I got the same error:
Screenshot
version: '3.7'
services:
mssql:
image: microsoft/mssql-server-windows-developer
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=myPassword
- MSSQL_PID=Enterprise
- attach_dbs="[{'dbName':'myDB','dbFiles'['c:\\db\\DB_Data.MDF','c:\\db\\DB_Log.LDF']}]"
ports:
- '1433:1433'
volumes:
- d:\dockershare\data:c:/db
I searched for quite a while and did not find anyone having a similar issue, most threads I found where about an error regarding "ConvertFrom-Json : Unrecognized escape sequence" stuff. Buy accident I saw a docker-compose file where the attach_db wasn't encapsulated in "". Maybe anyone can clarify why.
I changed this line:
- attach_dbs="[{'dbName':'myDB','dbFiles'['c:\\db\\DB_Data.MDF','c:\\db\\DB_Log.LDF']}]"
To this:
- attach_dbs=[{"dbName":"myDB","dbFiles"["c:\\db\\DB_Data.MDF","c:\\db\\DB_Log.LDF"]}]
And now it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With