2
votes

I'm trying to add an Azure Function project to a docker-compose file created in Visual Studio 2019 (16.7.6), but this causes the solution to fail to build.

(Docker for Windows 2.4.0.0 (48506), with WSL2 support enabled, running in Linux container mode on Windows 10 Pro 2004)

Steps to reproduce:

  1. Create a new solution with a Web Api project 'Web' that includes docker support.
  2. Add a new Azure Function project 'Func' with an Http trigger function and then added docker support via Visual Studio Add > Docker Support option.
  3. Add 'Container Orchestration Support' to Web project to generate a docker-compose.yml file that has the web app

At this point the solution builds debugging works for the web or func app in docker or docker-compose - all good.

When 'Func' project is added manually to docker-compose.yml the solution no longer builds:

CTC1031 Linux containers are not supported for Func project
Project: docker-compose
File: Microsoft.VisualStudio.Docker.Compose.targets
Line 303

However, I can run docker-compose fine from the command line:

docker-compose -f docker-compose.yml up

and both Web and Func app start up fine.

My docker-compose.yml file is

version: '3.4'

services:
  web:
    image: ${DOCKER_REGISTRY-}web
    build:
      context: .
      dockerfile: Web/Dockerfile

  func:
    image: ${DOCKER_REGISTRY-}func
    build:
      context: .
      dockerfile: Func/Dockerfile

Any ideas why I get the above error when building the solution in Visual Studio?

1

1 Answers

0
votes

Have the same issue. It seems that docker-compose project type allows to set up dependencies only to specific type of projects, like Sdk="Microsoft.NET.Sdk.Web", and does not allow to library projects like Sdk="Microsoft.NET.Sdk". Referencing Dockerfile from docker-compose.yml automatically sets up reference.

In case of wrong project type compose works, but compilation of docker-compose project fails.