Home > Software engineering >  Cannot build docker-compose project in visual studio
Cannot build docker-compose project in visual studio

Time:10-21

I have VS2019. I create console application .Net core 3.1. I add docker-compose project - Linux. I can build and run the console application, without the docker compose, and it creates Container.

When I build the Docker compose, I get the following error:

services.consoleapp7 must be a mapping

full output:

2>------ Rebuild All started: Project: docker-compose, Configuration: Debug Any CPU ------
Restored C:\Users\GiladSefti\source\repos\ConsoleApp7\ConsoleApp7\ConsoleApp7.csproj (in 15 ms).
1>ConsoleApp7 -> C:\Users\GiladSefti\source\repos\ConsoleApp7\ConsoleApp7\bin\Debug\netcoreapp3.1\ConsoleApp7.dll
2>docker-compose  -f "C:\Users\GiladSefti\source\repos\ConsoleApp7\docker-compose.yml" -f "C:\Users\GiladSefti\source\repos\ConsoleApp7\docker-compose.override.yml" -p dockercompose13777292865876941177 --ansi never config
2>services.consoleapp7 must be a mapping
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(209,5): error DT1001: services.consoleapp7 must be a mapping
2>Done building project "docker-compose.dcproj" -- FAILED.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped 

the file docker-compose.yml:

version: '3.4'

services:
  consoleapp7:
    image: ${DOCKER_REGISTRY-}consoleapp7
    build:
      context: .
      dockerfile: ConsoleApp7/Dockerfile

the file DockerFile :

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["ConsoleApp7/ConsoleApp7.csproj", "ConsoleApp7/"]
RUN dotnet restore "ConsoleApp7/ConsoleApp7.csproj"
COPY . .
WORKDIR "/src/ConsoleApp7"
RUN dotnet build "ConsoleApp7.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ConsoleApp7.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp7.dll"]

Also even before I compile, I see error in compose.override.yml

Incorrect type. Expected "object".      ConsoleApp7\docker-compose.override.yml

Pointing to

   consoleapp7:

compose.override.yml :

version: '3.4'
services:
  consoleapp7:

The project download:

https://drive.google.com/file/d/1D4rNS51S_dxY92vUvVqgnKy9TJYof0D4/view?usp=sharing

CodePudding user response:

Your Dockerfile and csproj file are at the same level.

Move your Dockerfile one folder up next to the sln file.

CodePudding user response:

When I remove setting Use docker Compose V2 from Docker desktop setting, Problem is solved

  • Related