1

I can build and run in Visual Studio successfully, but I got an error when I am trying to build a docker image(TestModule) from a visual studio that references 2 projects (Microsoft.Azure.Devices.Edge.Util + ModuleLib). Any idea what wrong with my dockerfile? To build, I right-click on project> build & push IoT edge Modules (I'm using vs extension tool).

projects:

 -TestModule
       |--Dockerfile
 -Microsoft.Azure.Devices.Edge.Util
 -ModuleLib

TestModule.csproj

...
    <ItemGroup>
        <ProjectReference Include="..\Microsoft.Azure.Devices.Edge.Util\Microsoft.Azure.Devices.Edge.Util.csproj" />
        <ProjectReference Include="..\ModuleLib\Microsoft.Azure.Devices.Edge.ModuleUtil.csproj" />
      </ItemGroup>
...

Build Errors:

Step 4/12 : COPY Microsoft.Azure.Devices.Edge.Util/*.csproj ./Microsoft.Azure.Devices.Edge.Util/
COPY failed: no source files were specified
[ERROR]: COPY failed: no source files were specified

UPDATE: * if you try to build this inside DOCKERFILE, using VS Code, the file will not be able to get access because the context of the docker is set to the module folder access. Hence the correct command should be for setting context at root folder.

Run in Powershell in the root folder (replaced myacr.azurecr.io with you container):

docker build --rm -f .\TestModule\Dockerfile.windows-amd64 -t myacr.azurecr.io/testmodule:0.0.7-windows-amd64 .;if ($?) { docker push myacr.azurecr.io/testmodule:0.0.7-windows-amd64 }

Dockerfile in TestModule (Dockerfile.windows-amd64):

  FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

COPY . .
RUN dotnet restore ./TestModule/TestModule.csproj

COPY . ./
RUN dotnet publish ./TestModule/TestModule.csproj -c Release -o out

FROM microsoft/dotnet:2.1-runtime-nanoserver-1809
WORKDIR /app
COPY --from=build-env /app/TestModule/out ./
ENTRYPOINT ["dotnet", "TestModule.dll"]

I created a DockerBuild.bat batch script in root project folder(replaced myacr.azurecr.io with you container), just enter as parameter a module name (lowercase) + version:

 @echo off
  Rem Run docker build image and push to Azure Container


  IF "%~1"==""  (
      ECHO Missing module name parameter lowercase. Ex: DockerBuild.bat modulename
      EXIT
  )

  IF "%~2"==""  (
      ECHO Missing version parameter. Ex: DockerBuild.bat modulename version
      EXIT
  )

  set modulename=%~1
  set version=%~2

  echo Module name: %modulename%
  echo Version: %version%

  docker build --rm -f .\%modulename%\Dockerfile.windows-amd64 -t myacr.azurecr.io/%modulename%:%version%-windows-amd64 .
  docker push myacr.azurecr.io/%modulename%:%version%-windows-amd64

  echo The Docker build has completed
Chuck O
  • 25
  • 8
  • I think I found something related to my issue: https://github.com/Azure/iotedge/issues/67 – Chuck O Mar 06 '19 at 13:21
  • if you try to build this inside DOCKERFILE, using VS Code, the file will not be able to get access because the context of the docker is set to the module folder access. So need to build to root folder that contains all the referenced folders! – Chuck O Mar 06 '19 at 13:33
  • Are you using [Azure IoT Edge for VS Code](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-edge) or [Azure IoT Tools (Preview) for VS](https://marketplace.visualstudio.com/items?itemName=vsc-iot.vsiotedgetools)? If you're using them you could use **contextPath** in module.json to set docker build context, the related thread: [https://github.com/Microsoft/vscode-azure-iot-edge/issues/137](https://github.com/Microsoft/vscode-azure-iot-edge/issues/137). – Erich Mar 13 '19 at 02:55

0 Answers0