gpt4 book ai didi

windows - Docker和NET Core 2.0,无法运行docker镜像

转载 作者:太空宇宙 更新时间:2023-11-03 17:08:27 24 4
gpt4 key购买 nike

我已经在我的 Windows 机器上安装了 Docker。目前,我已将 vsproject 设置为可以通过 Visual Studio 的“使用 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"]

最佳答案

我遇到了同样的问题。看起来,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

希望对您有所帮助!

关于windows - Docker和NET Core 2.0,无法运行docker镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com