Asp.netcore app in docker debian - c#

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 "

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?

mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled: not found

I have created the default WeatherForecast web api project with Docker support.
By default, the dockerfile is using aspnet: 6.0
But I would like to upgrade it to 6.0-jammy-chiseled. This is my dockerfile after I have updated it to 6.0-jammy-chiseled
FROM mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy-chiseled AS build
WORKDIR /src
COPY ["Weather2.csproj", "."]
RUN dotnet restore "./Weather2.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Weather2.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Weather2.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Weather2.dll"]
When I run it, I got an error:
mcr.microsoft.com/dotnet/aspnet:6.0-jammy-chiseled: not found
I try to pull the image manually with docker pull mcr.microsoft.com/dotnet/nightly/aspnet:6.0-jammy-chiseled and it pull without issue.
Based on the Docker file of the official sample app, I think that your Docker file should be revised as
FROM mcr.microsoft.com/dotnet/nightly/aspnet:6.0-jammy-chiseled AS base (add nightly in the image path)
and
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build (remove -chiseled as SDK has no need to be chiseled and Microsoft will not publish chiseled SDK but only chiseled runtime.

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

Pull access denied, repository does not exist or may require authorization: server message: insufficient_scope:authorization failed

I am having issues with building a dotnet core image. When I run docker pull mcr.microsoft.com/dotnet/sdk:3.1, this works but my dockerfile build is throwing the error 'failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed' when I do a docker build -t weatherapi -f Dockerfile . Here's my dockerfile below
FROM mcr.microsoft.com/dotnet/sdk:3.1
WORKDIR /app
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c release -o out
FROM mcr.microsoft.com/dotnet/aspnet:3.1
WORKDIR /app
EXPOSE 80
COPY --from=build /app/out .
ENTRYPOINT ["dotnet" "weather.dll"]
It looks like you've got a multi-stage Dockerfile but haven't named any stages. Specifically, the COPY --from=build /app/out . line references a stage named build that is not defined. This should resolve the issue (note the first line defines the build stage):
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /app
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c release -o out
FROM mcr.microsoft.com/dotnet/aspnet:3.1
WORKDIR /app
EXPOSE 80
COPY --from=build /app/out .
ENTRYPOINT ["dotnet" "weather.dll"]

docker container does not allocates the port

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?

Categories