I am not sure how to debug container start process.
I created a templated Blazor wasm hosted app (.NET 6) in VS 2022 and added docker support. Docker file configuration is default - I did not change anything in it
I have pushed this image to docker hub.
I have cleared all the images and containers from cache, docker images -a and docker ps -a return no data.
I execute docker pull on both developmen computer (Win11) and ubuntu server.
I run the container on both Win11 and ubuntu: docker run -dit -p 5000:80 username/imagename
On Win11 container is running in the background, status: UP and I can access my app on localhost:5000
However, on ubuntu container runs and exists (status: Exited (0) About 3 secs ago).
docker logs containername returns no data
docker inspect returns in config section: "Architecture": "amd64", "Os": "linux", "Entrypoint": [ "dotnet", "App.Server.dll" ] - so that looks OK
Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["TestApp/Server/TestApp.Server.csproj", "TestApp/Server/"]
COPY ["TestApp/Shared/TestApp.Shared.csproj", "TestApp/Shared/"]
COPY ["TestApp/Client/TestApp.Client.csproj", "TestApp/Client/"]
RUN dotnet restore "TestApp/Server/TestApp.Server.csproj"
COPY . .
WORKDIR "/src/TestApp/Server"
RUN dotnet build "TestApp.Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "TestApp.Server.csproj" -c Release -o
/app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestApp.Server.dll"]
Any ideas why I have different behavior on ubuntu server, and how can I debug this?
Related
I have a pretty simple Dockerfile that builds an API image.
Dockerfile:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:2.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
WORKDIR /src
COPY ["MyApp.Api/MyApp.Api.csproj", "MyApp.Api/"]
COPY ["MyApp.Common/MyApp.Common.csproj", "MyApp.Common/"]
COPY ["MyApp.Service/MyApp.Service.csproj", "MyApp.Service/"]
COPY ["MyApp.Repository/MyApp.Repository.csproj", "MyApp.Repository/"]
COPY ["MyApp.Data/MyApp.Data.csproj", "MyApp.Data/"]
COPY ["MyApp.Model/MyApp.Model.csproj", "MyApp.Model/"]
COPY ["MyApp.DTO/MyApp.DTO.csproj", "MyApp.DTO/"]
RUN dotnet restore "MyApp.Api/MyApp.Api.csproj"
COPY . .
WORKDIR "/src/MyApp.Api"
RUN dotnet build "MyApp.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.Api.dll"]
Building that way : docker build -f MyApp.Api/Dockerfile -t myapp-api:latest .
Running it under Windows works fine and doing an ls /app gives all the DLL/files I expect.
I then deployed to Docker Hub and tried to run it on a dev server I have under Debian 10 hosting several other containers.
However launching the app the same way doesn't give me the same result:
4aa6c81f67a1 myapp-api:latest "bash" 8 minutes ago Exited (0) 8 minutes ago dazzling_ramanujan
Strangely enough bash appears to be launched instead of dotnet.
I then commited this exited container to a new one and overrided the entrypoint in order to inspect the container and doing an ls /app shows me an empty folder while it's filled in Windows.
Did you encounter something similar? How to debug that ?
I'm trying to run simplest asp.net core 3.1 WebApplication inside docker as simple as possible but, docker does not binding host port.
Host: Windows 10
Container target: Linux
Docker version: 20.10.7
Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
EXPOSE 80
EXPOSE 443
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "WebApplication.csproj"
RUN dotnet build "WebApplication.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication.dll"]
Docker build command (ok)
docker build -t webapplication .
Docker run command (ok)
docker run webapplication -p 5000:80 -p 5001:443
When I try to access website on my localhost (http://localhost:5000) I'm getting This site can’t be reached. Running the docker ps returned ports information without host mapping port
As #marzelin correctly pointed out, you need to add the flag right after run.
It is impossible for me to access container with ASP.NET Core 3.1 application running inside.
Goal is to run application in container on port 5000. When I'm running it locally using standard VS profile I navigate to http://localhost:5000/swagger/index.html in order to load swaggerUI. I would like to achieve same thing using docker.
Steps to reproduce my issue:
Add dockerfile with exposed 5000 port and ENV ASPNETCORE_URLS variable:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:5000
EXPOSE 5000
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["myapp/myapp.csproj", "myapp/"]
RUN dotnet restore "myapp/myapp.csproj"
COPY . .
WORKDIR "/src/myapp/"
RUN dotnet build "myapp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "myapp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "myapp.dll"]
Build image
docker build -t myapp .
Run docker image:
docker run myapp -p 5000:5000
Running commands above with specific docker file results in this:
[21:28:42 INF] Starting host.
[21:28:42 INF] Now listening on: http://[::]:5000
[21:28:42 INF] Application started. Press Ctrl+C to shut down.
[21:28:42 INF] Hosting environment: Production
[21:28:42 INF] Content root path: /app
However, I can't access container using http://localhost:5000/swagger/index.html because of ERR_CONNECTION_REFUSED -> This site can't be reached.
I did get into container to check if host is running for sure, using:
docker exec -it containerId /bin/bash
cd /app
dotnet myapp.dll
what resulted in following error:
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://[::]:5000: address already in use.
Conclusion is that port inside the container is used, application is alive, it's just not accessible from outside.I don't know how to get inside of it.
Please point me into right direction.
UPDATE
Issue is solved, answer is posted below. However explanation why it was needed and how it works would be nice!
To solve the issue I had to manually add "--server.urls" to entrypoint like shown below:
ENTRYPOINT ["dotnet", "myapp.dll", "--server.urls", "https://+:5000"]
I solved the same issue in the following way:
Added the following in appsettings.json to force Kestrel to listen to port 80.
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://+:80"
}
}
}
Exposed the port in dockerfile
ENV ASPNETCORE_URLS=http://+:80
EXPOSE 80
ENTRYPOINT ["dotnet", "EntryPoint.dll"]
Ran the container using the below command.
docker run -p 8080:80 <image-name>:<tag>
The app exposed on http://localhost:8080/
I have successfully run "docker run". How do I browse my web app?
I have tried localhost:8000 and localhost:81 but no success.
Updated with docker ps -a
My dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["WebApplication4/WebApplication4.csproj", "WebApplication4/"]
RUN dotnet restore "WebApplication4/WebApplication4.csproj"
COPY . .
WORKDIR "/src/WebApplication4"
RUN dotnet build "WebApplication4.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebApplication4.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication4.dll"]
You are able to access localhost:52010 since the container that exposed the port 52010 is currently running, however the other containers have all exited. This is probably due to the fact that container ea7 was run with the persistent tail -f /dev/null command, while the other containers were run with the non-persistent bash command.
The reason for this could be that the image you are trying to run does not have any command that persists and as soon as the container is created all running tasks in it are completed and the container exits.
Please make sure webapplication4:dev has a persistent command in it to keep the container from exiting.
Hope this helps !
I have a Docker Swarm with multiple Raspberry Pis (raspbian light). I try to run
ASP.NET Core Containers on them as service / stack.
I have following Dockerfile:
FROM microsoft/dotnet:2.0-sdk AS build
WORKDIR /source
COPY WebApi.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /publish -r linux-arm /p:PublishWithAspNetCoreTargetManifest="false"
FROM microsoft/dotnet:2.0-runtime-deps-stretch-arm32v7
ENV ASPNETCORE_URLS http://+:80
WORKDIR /app
COPY --from=build /publish .
ENTRYPOINT [ "./WebApi" ]
What works:
Building & pushing the container image on my win10 laptop (till the sdk image is only available for x64) and running the container on a single raspberry node with docker run:
docker run --rm -it myrepo/myimage
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
(so the container can run and it's no arm vs x64 issue)
What don't work:
docker service create myrep/myimage
2n4ahyhgb3ju5rvo97tekh9vg
overall progress: 0 out of 1 tasks
1/1: no suitable node (unsupported platform on 3 nodes)
And of course docker stack deploy.
If I inspect the created image (or even the arm32v7 image from microsoft) it just states amd64 instead of arm.
"Architecture": "amd64",
"Os": "linux",
So is it a case of wrong meta data? Which is only checked by docker if you use swarm? How can I change that / make it run? Building a base image on my own? Do I miss something?
Edit 1
I tried it with the .NET Core 2.1 images and had the same behavior.
With the latest .NET Core 2.1 Preview 2 images released yesterday it finally works.
Update (add Dockerfile):
This simple one should do the trick:
FROM microsoft/dotnet:2.1-sdk-stretch-arm32v7 AS builder
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1
WORKDIR /src
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /publish -r linux-arm
FROM microsoft/dotnet:2.1-runtime-deps-stretch-slim-arm32v7
WORKDIR /app
COPY --from=builder /publish .
ENTRYPOINT [ "./MyService" ]
You can even build your image now on your raspberry pi. But be aware it´s still a (nice working) preview.