0

I want to run my web application with mssql db sample which has already existed on my localdb. I have made configurations. But I have an error like below altough My .mdf and .ldf files are in there.

My Files Directory


Docker-compose.yaml

version: '3.4'
services:
  mssql:
    image: "microsoft/mssql-server-windows-developer"
    container_name: mssql
    ports:
      - 1433:1433
    environment:
      ACCEPT_EULA: "Y"
      SA_PASSWORD: "Asdf1234"
      attach_dbs: '[{"dbName":"BlogAppDB","dbFiles":["C:\\DBs\\BlogAppDB.mdf","C:\\DBs\\BlogAppDB_log.ldf"]}]'
    # volumes:
    #   - BlogDB:/var/opt/mssql/data 
  client:
    build:
      dockerfile: Blog.Web/Dockerfile
      context: .
    depends_on:
      - mssql

Bash prompt

Successfully built a873eeb86600
Successfully tagged blogwebapplication_client:latest
Recreating mssql ... done
Recreating blogwebapplication_client_1 ... done
Attaching to mssql, blogwebapplication_client_1
client_1  | Hosting environment: Production
client_1  | Content root path: C:\app
client_1  | Now listening on: http://[::]:80
client_1  | Application started. Press Ctrl+C to shut down.
mssql     | VERBOSE: Starting SQL Server
mssql     | VERBOSE: Changing SA login credentials
mssql     | VERBOSE: Attaching 1 database(s)
mssql     | VERBOSE: Invoke-Sqlcmd -Query IF EXISTS (SELECT 1 FROM SYS.DATABASES WHERE NAME
mssql     |  = 'BlogAppDB') BEGIN EXEC sp_detach_db [BlogAppDB] END;CREATE DATABASE
mssql     | [BlogAppDB] ON (FILENAME = N'C:\DBs\BlogAppDB.mdf'),(FILENAME =
mssql     | N'C:\DBs\BlogAppDB_log.ldf') FOR ATTACH;
mssql     | Msg 5121, Level 16, State 2, Server E5F7E0B18B1B, Line 1
mssql     | The path specified by "C:\DBs\BlogAppDB.mdf" is not in a valid directory.
mssql     | VERBOSE: Started SQL Server.
mssql     |
mssql     | TimeGenerated            EntryType Message
mssql     | -------------            --------- -------
mssql     | 12/19/2019 9:53:33 AM FailureAudit Login failed. The login is from an untrus...
mssql     | 12/19/2019 9:53:33 AM        Error SSPI handshake failed with error code 0x8...
mssql     | 12/19/2019 9:55:11 AM FailureAudit Login failed. The login is from an untrus...
mssql     | 12/19/2019 9:55:11 AM        Error SSPI handshake failed with error code 0x8...
mssql     | 12/19/2019 9:55:33 AM FailureAudit Login failed. The login is from an untrus...
mssql     | 12/19/2019 9:55:33 AM        Error SSPI handshake failed with error code 0x8...
mssql     | 12/19/2019 9:56:46 AM  Information None
mssql     | 12/19/2019 9:57:03 AM FailureAudit Login failed. The login is from an untrus...
mssql     | 12/19/2019 9:57:03 AM        Error SSPI handshake failed with error code 0x8...

1 Answers1

0

Your data is on your local machine (host machine). It is not available in Docker (the Docker machine). You can map local machine directories to Docker machine ones using volumes. For example:

volumes:
  - C:\\DBs\\BlogAppDB.mdf","C:\\DBs\\BlogAppDB_log.ldf:/var/opt/mssql/data

In your question, you had commented out the volumes. But the volume was named BlogDB. If you want to persist data in the Docker machine, that's fine. But to map a directory from your local machine, you need to provide a path (e.g., ./my-directory/).

If the Windows-style path doesn't seem to be working out, check out this QA.

Neel Kamath
  • 1,188
  • 16
  • 34
  • I have tried to both //C/DBs/BlogAppDB.mdf and C:\\DBs\\BlogAppDB.mdf, but isn't working. I see this as a message in bash. ----> ERROR: for 7c77eff936f6_mssql Cannot create container for service mssql: invalid volume specification: '//C/DBs/BlogAppDB.mdf:/var/opt/mssql/data:rw' ERROR: for mssql Cannot create container for service mssql: invalid volume specification: '//C/DBs/BlogAppDB.mdf:/var/opt/mssql/data:rw' Encountered errors while bringing up the project. – CresphtonteS Dec 19 '19 at 10:46