I'm working on setting up a new project to use Docker Compose to deploy a web app and a database to two different containers for local development. When I save the compose file Visual Studio picks up the change and immediately runs docker-compose and it runs successfully. My images get created and I'm able to start them from the command line without issue. The second I try to build the solution (using any of the many ways to do so) the build task CreateComposeVsGeneratedFiles fails and gives me an error message that simply is not helpful:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(291,5): error : Value cannot be null.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(291,5): error : Parameter name: stream
I've tried cleaning the solution performing a rebuild with no success. I also tried removing all of the local images and containers to see if maybe there was a force command not being applied somewhere but that didn't work either. I've also looked through many issues on the web, some point to old problems that were closed as they were fixed in earlier releases of VS while others point to issues with doing Azure Functions in a container which I am not doing.
Here is my current compose file:
version: '3.4'
services:
mvc:
image: ${DOCKER_REGISTRY-}tsacodingchallengesubmissionsmvc
build:
context: .
dockerfile: Tsa.CodingChallenge.Submissions.Mvc/Dockerfile
depends_on:
- db
db:
image: ${DOCKER_REGISTRY-}tsacodingchallengesubmissionsdb
build:
context: .
dockerfile: Tsa.CodingChallenge.Submissions.Database/Dockerfile
My override file:
version: '3.4'
services:
mvc:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_HTTPS_PORT=44327
ports:
- "11467:80"
- "44327:443"
volumes:
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
db:
ports:
- "1438:1433"
The MVC Dockerfile:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY Tsa.CodingChallenge.Submissions.Mvc/Tsa.CodingChallenge.Submissions.Mvc.csproj Tsa.CodingChallenge.Submissions.Mvc/
COPY Tsa.CodingChallenge.Submissions.Core/Tsa.CodingChallenge.Submissions.Core.csproj Tsa.CodingChallenge.Submissions.Core/
RUN dotnet restore Tsa.CodingChallenge.Submissions.Mvc/Tsa.CodingChallenge.Submissions.Mvc.csproj
COPY . .
WORKDIR /src/Tsa.CodingChallenge.Submissions.Mvc
RUN dotnet build Tsa.CodingChallenge.Submissions.Mvc.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Tsa.CodingChallenge.Submissions.Mvc.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Tsa.CodingChallenge.Submissions.Mvc.dll"]
And my DB Dockerfile:
FROM mcr.microsoft.com/mssql/server:2017-latest
COPY scripts/Tsa.CodingChallenge.Submissions.Database_Create.sql /create-db.sql
COPY scripts/create-sql-database.sh /
ENV ACCEPT_EULA Y
ENV SA_PASSWORD rIMdEnfnHj395cFO
RUN /create-sql-database.sh
CMD [ "/opt/mssql/bin/sqlservr" ]
I'm currently running the following tool set:
Let me know if you need more details or would like the source code. This project will eventually be made open source so I can post it GitHub ahead of time if need be.
@tj-cappelletti Thanks for all the details! I'm going to try this out and see what I can find.
@tj-cappelletti, we did some investigating and have a hunch. Is there any kind of project file (anything *proj) alongside the Database' Dockerfile (Tsa.CodingChallenge.Submissions.DatabaseDockerfile)? For example, a class library with database helpers?
One of the things our code is trying to do is figure out if there's a project associated with any given Dockerfile referenced by the docker-compose.yml. If so, we try to figure out what the project type is (e.g., maybe it's ASP.NET Core), and based on that, we create the generated docker-compose.vs.debug.g.yml file(s). We do this by determining if there's a template file for the project type. Assuming there is a project beside that Dockerfile, most likely it is not one of our supported types, and there's no template.
The solution in this case would be to move that DB Dockerfile somewhere else (e.g. into a subfolder) so that it is not alongside a project file, and update the docker-compose.yml accordingly.
We're going to work on improving this error message so that it isn't so unhelpful.
@bwateratmsft your hunch was correct, the database dockerfile is sitting next to a sqlproj file. I moved the file to separate directory and now everything works as expected. Thanks for looking into it!
@tj-cappelletti Glad to hear it worked. I'll close this item, meanwhile I have filed an item to our internal bug database to work on that unhelpful error message.
Most helpful comment
@tj-cappelletti, we did some investigating and have a hunch. Is there any kind of project file (anything *proj) alongside the Database' Dockerfile (Tsa.CodingChallenge.Submissions.DatabaseDockerfile)? For example, a class library with database helpers?
One of the things our code is trying to do is figure out if there's a project associated with any given Dockerfile referenced by the docker-compose.yml. If so, we try to figure out what the project type is (e.g., maybe it's ASP.NET Core), and based on that, we create the generated docker-compose.vs.debug.g.yml file(s). We do this by determining if there's a template file for the project type. Assuming there is a project beside that Dockerfile, most likely it is not one of our supported types, and there's no template.
The solution in this case would be to move that DB Dockerfile somewhere else (e.g. into a subfolder) so that it is not alongside a project file, and update the docker-compose.yml accordingly.
We're going to work on improving this error message so that it isn't so unhelpful.