我在我的Windows机器上安装了Docker。目前我的vsproject设置可以通过Visual Studio的“Run with Docker”按钮运行Web应用程序。
但是当我进入powershell并使用
构建我自己的图像时docker build -t blog .
输出:
PS C:\Users\Acina\sites\Blog> docker build -t blog .
unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\Users\Acina\sites\Blog
\Dockerfile: The system cannot find the file specified.
PS C:\Users\Acina\sites\Blog> cd Blog
PS C:\Users\Acina\sites\Blog\Blog> docker build -t blog .
Sending build context to Docker daemon 3.584kB
Step 1/6 : FROM microsoft/aspnetcore:2.0
---> 452ca00e5495
Step 2/6 : ARG source
---> Using cache
---> 73e5e625c084
Step 3/6 : WORKDIR /app
---> Using cache
---> 9cb30c8476e4
Step 4/6 : EXPOSE 80
---> Using cache
---> 6d1a8f3cc094
Step 5/6 : COPY ${source:-obj/Docker/empty} .
---> Using cache
---> aedf4f7d5b5d
Step 6/6 : ENTRYPOINT dotnet Blog.dll
---> Using cache
---> d3d785062d3f
Successfully built d3d785062d3f
Successfully tagged blog:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and director
ies added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions f
or sensitive files and directories.
PS C:\Users\Acina\sites\Blog\Blog>
但是,当我尝试使用:docker run -p 5000:5000 blog
PS C:\Users\Acina\Documents\Visual Studio 2017\Projects\Blog\Blog> docker run -p 5000:5000 blog
[ERROR] docker : Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
[ERROR] At line:1 char:1
[ERROR] + docker run -p 5000:5000 blog
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : NotSpecified: (Did you mean to...tnet SDK from: :String) [], Remote
[ERROR] Exception
[ERROR] + FullyQualifiedErrorId : NativeCommandError
[ERROR]
[ERROR] http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
[ERROR]
从目前为止我的研究看来,似乎docker无法找到我的.dll文件,该文件位于Projects \ Blog \ Blog \ bin \ Debug \ netcoreapp2.0 \ Blog.dll
下这是我的Dockerfile
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/empty} .
ENTRYPOINT ["dotnet", "Blog.dll"]
答案 0 :(得分:0)
我遇到了同样的问题。看起来,dotnet core 2.0在运行dotnet restore
之前就已经完成了。但这是个问题,因为你需要SDK(microsoft / dotnet:2.0-sdk)。因此,如果您想进行开发,只需使用sdk image替换runtime即可。但是,如果您想要生产版本,可以使用:
FROM microsoft/dotnet:2.0-sdk
WORKDIR /app
# If you need to restore, publish etc...
#COPY *.csproj ./
#RUN dotnet restore
# build runtime image
FROM microsoft/dotnet:2.0-runtime
WORKDIR /app
COPY ${source:-obj/Docker/empty} .
ENTRYPOINT ["dotnet", "Blog.dll"]
以下是生产解决方案的原始示例:https://github.com/dotnet/dotnet-docker-samples/tree/master/dotnetapp-prod
希望有所帮助!
答案 1 :(得分:0)
这是Visual Studio" Docker"模板工作 - 它假定构建的结果仅用于Visual Studio。
我建议您查看此guide in the Docker documentation。它展示了如何在容器中正确构建Docker。