docker container does not allocates the port - c#

I'm trying to place my simple REST Api (built on asp.net core) into docker container.
I have the following docker file
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["/", "SimpleApp.Api/"]
RUN dotnet restore "SimpleApp.Api/SimpleApp.Api.csproj"
COPY . .
WORKDIR "/src/SimpleApp.Api"
RUN dotnet build "SimpleApp.Api.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "SimpleApp.Api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SimpleApp.Api.dll"]
I can successfully build an image from this file, but when I run the container I can't, for example, call none of the URLs + I have swagger on top of my API, so it should show me a page but it doesn't.
docker run -d --name "mySimpleContainer" "MySimpleApp:latest" --ports 5000:80
The url like localhost:5000 doesn't work so firstly I checked the logs:
........
2019-02-02 13:37:17.3635||DEBUG|Microsoft.AspNetCore.Hosting.Internal.WebHost|Loaded hosting startup assembly SimpleApp.Api
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
looks good to me. Secondary, I checked if 5000 is busy or not... and suddenly it's not!!!
to check the port I used netstat -an | find ":5000"
Does anyone know where I failed?

Related

Exception on .setting file Save() function on docker Linux: ClientConfigurationHost::OpenStreamForWrite

im working on a net7.0 ASP.NET Core Wen API project with linux docker build.
In my application i need to save some settings on a .setting file. Thats working well when i run my application on IIS Express on Windows.
Here is a simpel code example:
ApplicationSettings.Default.Test = "Test"
ApplicationSettings.Default.Save();
When i running this code on Docker build:
I get this exception on the .Save() functon:
"Failed to save settings: An error occurred loading a configuration file: An unexpected error occurred in 'ClientConfigurationHost::OpenStreamForWrite '' '''."
This docker file was created by visual studio.
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["ShippApiCollection/ShippApiCollection.csproj", "ShippApiCollection/"]
RUN dotnet restore "ShippApiCollection/ShippApiCollection.csproj"
COPY . .
WORKDIR "/src/ShippApiCollection"
RUN dotnet build "ShippApiCollection.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ShippApiCollection.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ShippApiCollection.dll"]
Anybody had the same issue and can help me here?

Asp.NET Core WebAPI not running in docker container

When I try to run my ASP.Net Core web api in a docker container, the application exitst early.
My Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://*:5000
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . ./
RUN dotnet restore
FROM build AS publish
RUN dotnet publish -c Release -o /out/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /out/publish .
ENTRYPOINT ["dotnet", "WebService.dll"]
But when i try to run this container the only log thats displayed is this
2022/08/11 09:11:20.802 | Warn | | Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository| Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
and the container exitst with exit code 139.
What am I doing wrong?
Th data Protection stores keys in the HOME directory (/root/.aspnet/DataProtection-Keys) so when the container restart the keys will be lost, and it might crash the service.
Add a Volume to
root/.aspnet/DataProtection-Keys
To check if the error is something else, please build in the debug mood
RUN dotnet publish --output /app/ --configuration Debug

How can I run a Docker container made for use in Heroku, in a localhost in my computer?

I have a docker image with a simple .net core API built in it, it works fine when I push it to heroku, but I am having troubles setting it to run in my localhost to test it locally.
I have this line in my Dockerfile
CMD ASPNETCORE_URLS=http://*:$PORT dotnet test-api.dll
But I can't make it run in "localhost:7050"
I am running the image with the following command
docker run -e PORT=7050 --rm --name api-container test-api
The problem is, it runs fine, but in a strange location, it says Now listening on: http://[::]:80
And I can't access that URL.
Of course, I can just do a simple dotnet run, and test it in the port configured, but I would like to test running a container in my computer, if that makes any sense.
The full Dockerfile is bellow, if it helps
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY . .
RUN dotnet restore
RUN dotnet build --no-restore -c Release -o /app
FROM build AS publish
RUN dotnet publish --no-restore -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
# Padrão de container ASP.NET
# ENTRYPOINT ["dotnet", "CarterAPI.dll"]
# Opção utilizada pelo Heroku
CMD ASPNETCORE_URLS=http://*:$PORT dotnet testeApi.dll

Configuring Docker to create a container for an Angular App

I am trying to get a default Angular App working inside a Docker container. Here are the steps I have followed:
1) Open Visual Studio 2017 and select: File/New/Project.
2) Select ASP.NET Core Web Application. Click OK.
3) Select .NET Core 2.2 and Angular. I notice that 'Enable Docker Support' is greyed out. Not sure why. Tried the first three steps in Visual Studio 2019 and it is the same. Untick Configure for HTTPS. Click OK.
4) Right click on the project and select Add/Container Orchestration Support. Select the Container Orchestration as Docker Compose and the target OS as Linux.
5) Rebuild the app
When I launch the app I see this:
My Docker File looks like this:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["Web/WebSPA/WebSPA.csproj", "Web/WebSPA/"]
RUN dotnet restore "Web/WebSPA/WebSPA.csproj"
COPY . .
WORKDIR "/src/Web/WebSPA"
RUN dotnet build "WebSPA.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebSPA.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebSPA.dll"]
I saw another question, which suggested changing the DockerFile to something like this:
ARG NODE_IMAGE=node:8.11
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80
FROM ${NODE_IMAGE} as node-build
WORKDIR /web
COPY src/Web/WebSPA .
RUN npm install
RUN npm run build:prod
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY scripts scripts/
COPY src/Web/*/*.csproj /src/csproj-files/
COPY . .
COPY --from=node-build /web/wwwroot /src/src/Web/WebSPA/wwwroot/
WORKDIR /src/src/Web/WebSPA
RUN dotnet publish -c Release -o /app
FROM build AS publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebSPA.dll"]
However, it made no difference.

Asp.netcore app in docker debian

I have problem to run my container in docker, my docker is host on a server linux debian
this is my docker file
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 5000
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY *.sln ./
COPY DockerWebPage/DockerWebPage.csproj DockerWebPage/
RUN dotnet restore
COPY . .
WORKDIR /src/DockerWebPage
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "DockerWebPage.dll"]
and this is my console output:
root#vps564358:~# docker build -t dockerwebpage:dev /home/Container
Sending build context to Docker daemon 352MB
Step 1/18 : too much code for send all console build
b1dd0b04c119: Pull complete
91ea08ab0cc9: Pull complete
7f2893df5d93: Pull complete
6ca202fa6c2e: Pull complete
31b4abd59648: Pull complete
Digest: sha256:1e4043c2484157e029d6b09a3149ebd01c5122f6b62f0a1b6c6f54b90500ea4b
Status: Downloaded newer image for microsoft/aspnetcore-build:2.0
---> e4e43a027c0b
Step 6/18 : WORKDIR /src
---> bf0be7525f14
Removing intermediate container 9ff4196e50dc
Step 7/18 : COPY *.sln ./
No source files were specified
root#vps564358:~# docker run -d -p 5000:5000 dockerwebpage:dev
9fe41e5b2237364e141ed575c02afc02755b8a751ba65e57a395a8b633b5d022
so i think after that my web app could work, but when i try to connect to my site i have a error :"Connetion denied from "

Categories