无法 运行 docker 容器
Unable to run docker container
我想 运行 我的 .NET MVC 应用程序变成 docker 图像:但我无法测试它。
这是我的 Dockerfile:
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /DataHandlerService
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /DataHandlerService
COPY --from=build-env /DataHandlerService/out .
ENTRYPOINT ["dotnet", "DataHandlerService.dll"]
图像构建成功,但是当我 运行 docker container run datahandler
我得到的是:
{"EventId":60,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository","Message":"Storing
keys in a directory \u0027/root/.aspnet/DataProtection-Keys\u0027 that
may not be persisted outside of the container. Protected data will be
unavailable when container is destroyed.","State":{"Message":"Storing
keys in a directory \u0027/root/.aspnet/DataProtection-Keys\u0027 that
may not be persisted outside of the container. Protected data will be
unavailable when container is
destroyed.","path":"/root/.aspnet/DataProtection-Keys","{OriginalFormat}":"Storing
keys in a directory \u0027{path}\u0027 that may not be persisted
outside of the container. Protected data will be unavailable when
container is destroyed."}}
{"EventId":35,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager","Message":"No
XML encryptor configured. Key {90a759c1-0f7a-417f-90e1-6b46c6f05b6a}
may be persisted to storage in unencrypted
form.","State":{"Message":"No XML encryptor configured. Key
{90a759c1-0f7a-417f-90e1-6b46c6f05b6a} may be persisted to storage in
unencrypted
form.","KeyId":"90a759c1-0f7a-417f-90e1-6b46c6f05b6a","{OriginalFormat}":"No
XML encryptor configured. Key {KeyId:B} may be persisted to storage in
unencrypted form."}}
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now
listening on: http://[::]:80","State":{"Message":"Now listening on:
http://[::]:80","address":"http://[::]:80","{OriginalFormat}":"Now
listening on: {address}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Application
started. Press Ctrl\u002BC to shut
down.","State":{"Message":"Application started. Press Ctrl\u002BC to
shut down.","{OriginalFormat}":"Application started. Press Ctrl\u002BC
to shut down."}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Hosting
environment: Production","State":{"Message":"Hosting environment:
Production","envName":"Production","{OriginalFormat}":"Hosting
environment: {envName}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Content
root path: /DataHandlerService/","State":{"Message":"Content root
path:
/DataHandlerService/","contentRoot":"/DataHandlerService/","{OriginalFormat}":"Content
root path: {contentRoot}"}}
当你 运行 它时你没有映射任何端口,所以你无法到达容器。除此之外,您的容器似乎 运行 还不错。
尝试
docker run -p 7242:80 -d datahandler
然后您应该可以通过 http://localhost:7242/
访问该应用程序
我想 运行 我的 .NET MVC 应用程序变成 docker 图像:但我无法测试它。
这是我的 Dockerfile:
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /DataHandlerService
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /DataHandlerService
COPY --from=build-env /DataHandlerService/out .
ENTRYPOINT ["dotnet", "DataHandlerService.dll"]
图像构建成功,但是当我 运行 docker container run datahandler
我得到的是:
{"EventId":60,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository","Message":"Storing keys in a directory \u0027/root/.aspnet/DataProtection-Keys\u0027 that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.","State":{"Message":"Storing keys in a directory \u0027/root/.aspnet/DataProtection-Keys\u0027 that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.","path":"/root/.aspnet/DataProtection-Keys","{OriginalFormat}":"Storing keys in a directory \u0027{path}\u0027 that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed."}} {"EventId":35,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager","Message":"No XML encryptor configured. Key {90a759c1-0f7a-417f-90e1-6b46c6f05b6a} may be persisted to storage in unencrypted form.","State":{"Message":"No XML encryptor configured. Key {90a759c1-0f7a-417f-90e1-6b46c6f05b6a} may be persisted to storage in unencrypted form.","KeyId":"90a759c1-0f7a-417f-90e1-6b46c6f05b6a","{OriginalFormat}":"No XML encryptor configured. Key {KeyId:B} may be persisted to storage in unencrypted form."}} {"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://[::]:80","State":{"Message":"Now listening on: http://[::]:80","address":"http://[::]:80","{OriginalFormat}":"Now listening on: {address}"}} {"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Application started. Press Ctrl\u002BC to shut down.","State":{"Message":"Application started. Press Ctrl\u002BC to shut down.","{OriginalFormat}":"Application started. Press Ctrl\u002BC to shut down."}} {"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Hosting environment: Production","State":{"Message":"Hosting environment: Production","envName":"Production","{OriginalFormat}":"Hosting environment: {envName}"}} {"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Content root path: /DataHandlerService/","State":{"Message":"Content root path: /DataHandlerService/","contentRoot":"/DataHandlerService/","{OriginalFormat}":"Content root path: {contentRoot}"}}
当你 运行 它时你没有映射任何端口,所以你无法到达容器。除此之外,您的容器似乎 运行 还不错。
尝试
docker run -p 7242:80 -d datahandler
然后您应该可以通过 http://localhost:7242/
访问该应用程序