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