【问题标题】:The path specified by "C:\DBs\BlogAppDB.mdf" is not in a valid directory“C:\DBs\BlogAppDB.mdf”指定的路径不在有效目录中
【发布时间】:2020-04-11 18:10:58
【问题描述】:

我想使用我的 localdb 上已经存在的 mssql db 示例运行我的 Web 应用程序。我已经做了配置。但是我有一个像下面这样的错误,我的 .mdf 和 .ldf 文件在那里。

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 提示

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

【问题讨论】:

    标签: sql docker docker-compose environment-variables containers


    【解决方案1】:

    您的数据在您的本地机器(主机)上。它在 Docker(Docker 机器)中不可用。您可以使用卷将本地机器目录映射到 Docker 机器目录。例如:

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

    在您的问题中,您已经注释掉了这些卷。但是该卷被命名为BlogDB。如果你想在 Docker 机器中持久化数据,那很好。但要从本地机器映射目录,您需要提供路径(例如,./my-directory/)。

    如果 Windows 风格的路径似乎不起作用,请查看此QA

    【讨论】:

    • 我已经尝试过 //C/DBs/BlogAppDB.mdf 和 C:\\DBs\\BlogAppDB.mdf,但是没有用。我认为这是 bash 中的一条消息。 ----> 错误:对于 7c77eff936f6_mssql 无法为服务 mssql 创建容器:无效的卷规范:'//C/DBs/BlogAppDB.mdf:/var/opt/mssql/data:rw' 错误:对于 mssql 无法创建容器service mssql: invalid volume specification: '//C/DBs/BlogAppDB.mdf:/var/opt/mssql/data:rw' 在启动项目时遇到错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多