none
Attaching a SQL Server database to a Docker container throws error- Docker for Windows RRS feed

  • Question

  •  I am using the below command in Powershell and Docker for Windows (Windows 10 Pro)

    docker run -d -p 1433:1433 -e sa_password=Pass2017 -e ACCEPT_EULA=Y -v c:/mvc_projects/SampleDb:c:/mvc_projects/SampleDb -e attach_dbs="[{'dbName':'AdventureWorksDW2008R2_Data','dbFiles': ['c:\\mvc_projects\\SampleDb\\AdventureWorksDW2008R2_Data.mdf','c:\\mvc_projects\\SampleDb\\AdventureWorksDW2008R2_Log.ldf']}]" microsoft/mssql-server-windows

    Below is the error

    VERBOSE: Starting SQL Server
    
        docker : Sqlcmd: 'AdventureWorksDW2008R2_Data";CREATE DATABASE 
        "AdventureWorksDW2008R2_Data" ON (FILENAME = 
        N'c:\infra_mvc_projects\SampleDb\AdventureWorksDW2008R2_Data.mdf'),
        (FILENAME = 
        N'c:\infra_mvc_projects\SampleDb\AdventureWorksDW2008R2_Log.ldf') FOR 
        ATTACH ;"': Unexpected 
        argument. Enter '-?' for help.
        At line:1 char:1
        + docker logs 673
        + ~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (Sqlcmd: 'Advent... '-?' for 
        help.:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
    
        VERBOSE: Changing SA login credentials
        VERBOSE: Attaching 1 database(s)
        VERBOSE: Invoke-Sqlcmd -Query sp_detach_db 
        "AdventureWorksDW2008R2_Data";CREATE
        DATABASE "AdventureWorksDW2008R2_Data" ON (FILENAME = 
        N'c:\infra_mvc_projects\SampleDb\AdventureWorksDW2008R2_Data.mdf'),
        (FILENAME = 
        N'c:\infra_mvc_projects\SampleDb\AdventureWorksDW2008R2_Log.ldf') FOR 
        ATTACH ;
        VERBOSE: Started SQL Server
    • The container gets created and able to open in Sql server management studio. But unable to attach the database with the above error.
    • Docker Version:      17.06.2-ce
    Thursday, October 5, 2017 5:09 AM

Answers

  • Hey Shivakv,

    It looks like you're experiencing the same issue as reported in this GitHub issue: https://github.com/Microsoft/mssql-docker/issues/174

    Per the solution posted over in GitHub, the latest developer and express sqlserver images should work with setting the ATTACH_DBs environmental var. Try out this fix and see if it doesn't work and we can go from there. Thanks!

    Craig
    • Proposed as answer by WithinRafaelMVP Thursday, October 26, 2017 7:33 AM
    • Marked as answer by Shivakv Wednesday, November 1, 2017 7:17 AM
    Thursday, October 19, 2017 9:34 PM

All replies

  • Hey Shivakv,

    It looks like you're experiencing the same issue as reported in this GitHub issue: https://github.com/Microsoft/mssql-docker/issues/174

    Per the solution posted over in GitHub, the latest developer and express sqlserver images should work with setting the ATTACH_DBs environmental var. Try out this fix and see if it doesn't work and we can go from there. Thanks!

    Craig
    • Proposed as answer by WithinRafaelMVP Thursday, October 26, 2017 7:33 AM
    • Marked as answer by Shivakv Wednesday, November 1, 2017 7:17 AM
    Thursday, October 19, 2017 9:34 PM
  • Hi Craig,

    Thank you for the response. The latest developer and express sqlserver image works just fine.

    Appreciate your help.

    Regards,
    Shiva


    • Marked as answer by Shivakv Wednesday, November 1, 2017 7:17 AM
    • Unmarked as answer by Shivakv Wednesday, November 1, 2017 7:17 AM
    Thursday, October 26, 2017 7:31 AM