Mssql-docker: Error using attach_dbs with mssql images and docker compose

Created on 9 May 2017  路  3Comments  路  Source: microsoft/mssql-docker

Hi,
Reference closed issue #40

I am also have a problem running the attach_dbs from docker-compose. Running the exact same command via docker run works just fine. The container starts just fine, I can connect and validate that the volume (c:\temp) is there and I can see the mdf/ldf file.

Below is my docker-compose file and the error I am receiving.

Thanks

docker-compose
version: '3'
services:
db:
image: microsoft/mssql-server-windows
environment:
sa_password: "P@ssword!"
ACCEPT_EULA: "Y"
attach_dbs: "[{'dbName':'DemoAE','dbFiles':['C:\temp\DemoAE.mdf','C:\temp\DemoAE.ldf']}]"
volumes:

  • "c:/temp:c:/temp"
    tty: true
    networks:
    default:
    ipv4_address: 192.168.1.101

Error:
Compose starts but error attaching db's:
db_1 | ConvertFrom-Json : Unrecognized escape sequence. (49): [{'dbName':'DemoAE',
db_1 | 'dbFiles':['C:\temp\DemoAE.mdf','C:\temp\DemoAE.ldf']}]
db_1 | At C:\start.ps1:36 char:30
db_1 | + $dbs = $attach_dbs_cleaned | ConvertFrom-Json
db_1 | + ~~~~
db_1 | + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentEx
db_1 | ception
db_1 | + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Co
db_1 | mmands.ConvertFromJsonCommand

mssql-server-windows

Most helpful comment

@richmccloud Try this:
attach_dbs: "[{'dbName':'DemoAE','dbFiles':['C:\\\\temp\\\\DemoAE.mdf','C:\\\\temp\\\\DemoAE.ldf']}]"

All 3 comments

Correction: there are double slashes in the attach_dbs:
attach_dbs: "[{'dbName':'DemoAE','dbFiles':['C:\\temp\\DemoAE.mdf','C:\\temp\\DemoAE.ldf']}]"

Single slashes results in an error starting compose.

@richmccloud Try this:
attach_dbs: "[{'dbName':'DemoAE','dbFiles':['C:\\\\temp\\\\DemoAE.mdf','C:\\\\temp\\\\DemoAE.ldf']}]"

You probably need to replace : with = . I was able to attach database with following docker_compose.yml:

version:` '3'

services:
    db:
        image: microsoft/mssql-server-windows-express
        ports:
            - "1433:1433"
        environment:
            - ACCEPT_EULA=Y
            - SA_PASSWORD=P@ssword!
            - attach_dbs="[{'dbName':'test','dbFiles':['C:\\DATA\\test.mdf','C:\\DATA\\test_log.ldf']}]"
        volumes:
            - ./data:C:/DATA
Was this page helpful?
0 / 5 - 0 ratings