Visual Studio 2017 15.3 Dockerize数据库项目

时间:2017-08-15 01:09:16

标签: sql-server visual-studio docker-compose visual-studio-2017

拥有两个项目的Visual Studio 2017(15.3)解决方案:

  • 用ASP.NET Core 2 MVC编写的API
  • 数据库项目

我能够轻松地“停靠”MVC项目(右键单击,添加Docker支持),但在尝试将数据库项目停靠时,不断收到错误:Value cannot be null. Parameter name: stream。我的Google-fu让我失望; closest resource found is for Visual Studio 15.2

到目前为止我如何设置数据库项目

将Dockerfile添加到root:

FROM microsoft/mssql-server-linux:latest
EXPOSE 1433
ENV ACCEPT_EULA=Y
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV MSSQL_TCP_PORT=1433

# Add Database project output from VS build process
RUN mkdir --parents /_scripts/generated
COPY ./_scripts /_scripts/
COPY ./_scripts/generated/*.sql /_scripts/generated/
# Add shell script that starts MSSQL server, waits 60 seconds, then executes script to build out DB (script generated from VS build process)
CMD /bin/bash /_scripts/entrypoint.sh

修改了docker-compose.yml文件以包含新项目

version: '3'

services:
  webapp-api-service:
    image: webapp-api
    build:
      context: ./src/API
      dockerfile: Dockerfile

  webapp-db-service:
    image: webapp-db
    build:
      context: ./src/Database
      dockerfile: Dockerfile

修改了docker-composeoverride.yml文件以公开dev SSMS访问的端口

version: '3'

services:
  webapp-api-service:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "80"

  webapp-db-service:
    ports:
      - "1433"

这是构建输出

2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(279,5): error : Value cannot be null.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(279,5): error : Parameter name: stream
2>Done building project "docker-compose.dcproj" -- FAILED.

提前致谢!

2 个答案:

答案 0 :(得分:1)

昨天我遇到了同样的问题。我刚刚通过删除数据库服务的构建部分来解决它。我现在只需要手动构建数据库项目。

答案 1 :(得分:0)

您可以将名为AppType.cache的文件添加到/obj/Docker,并将内容AspNetCore作为解决方法。