我可以在Visual Studio中成功构建并运行,但是在尝试从引用2个项目(Microsoft.Azure.Devices.Edge.Util + ModuleLib)的Visual Studio构建docker映像(TestModule)时出现错误。 )。知道我的dockerfile有什么问题吗?要构建,我右键单击project>构建并推送IoT Edge模块(我正在使用vs扩展工具)。
项目:
-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>
...
构建错误:
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
更新: * 如果您尝试使用VS Code在DOCKERFILE中构建此文件,则该文件将无法访问,因为docker的上下文设置为模块文件夹访问。因此,正确的命令应该是用于在根文件夹中设置上下文。
在Powershell的根文件夹中运行(已将myacr.azurecr.io替换为您的容器):
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 }
TestModule中的Dockerfile(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"]
我在根项目文件夹中创建了一个DockerBuild.bat批处理脚本(用您的容器替换了myacr.azurecr.io),只需输入模块名称(小写)+版本作为参数即可
@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