Home > OS >  Unable to run docker container
Unable to run docker container

Time:03-09

I want to run my .NET MVC application into a docker image: but I'm unable to test it.

Here is my 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"]

the image builds successfully but when I run docker container run datahandler here is what I get:

{"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}"}}

CodePudding user response:

You don't map any ports when you run it, so you can't reach the container. Your container seems to run fine aside from that.

Try

docker run -p 7242:80 -d datahandler

Then you should be able to get to the app at http://localhost:7242/

  • Related