2

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...

attach dbs output

3 Answers 3

9

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I had to insert ":" after dbFiles. This worked for me:

version: '3.8'

services:
 sql_server:
  image: microsoft/mssql-server-windows-express
  isolation: hyperv
  restart: always
  environment:
   - ACCEPT_EULA=Y
   - SA_PASSWORD=MyPwd
   - attach_dbs=[{"dbName":"myDB","dbFiles":["c:\\temp\\myDB.mdf","c:\\temp\\myDB.ldf"]}]
  ports:
   - '1433:1433'
  volumes:
   - C:/temp/:C:/temp/

Comments

0

Correct json string is: - attach_dbs=[{"dbName":"myDB","dbFiles":"c:\\db\\DB_Data.MDF","c:\\db\\DB_Log.LDF"]}]

1 Comment

You are missing a [ in your example after "dbFiles":

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.