I have a simple API which I am running in Docker
When I run the command to run my image I get the output below
docker run newapi:latest mee
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /api
This all looks fine
However, I get connection refused when using Postman
http://localhost/weatherforecast
Any idea what is wrong?
My docker file is:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /api
# 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
EXPOSE 80
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /api
COPY --from=build-env /api/out .
ENTRYPOINT ["dotnet", "api.dll"]
As you can see I am exposing port 80
I can use http://localhost:8080 but I just want to be able to use http://localhost
When you run the docker try mapping the port
docker run -p 80:80 newapi:latest mee
Related
I run commands to build and publish the docker image to registry but it fails with this error:
MSBUILD : error MSB1009: Project file does not exist.
Switch: ./Project.Api/Project.Api.csproj
Project structure
src
|--Project.Api
| |--Project.Api.csproj
|-- Dockerfile
tests
azure-pipelines.yml
Docker task in pipeline
stages:
...
- stage: build
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: build_container
displayName: 'Build docker container image'
steps:
- bash: |
docker login -u $(REGISTRY_USER) -p $REGISTRY_PASSWORD $(REGISTRY_URL)
docker build -t $(REGISTRY_URL)/$(IMAGE_REPOSITORY):kkk . -f $(build.sourcesDirectory)/src/Dockerfile
docker push $(REGISTRY_URL)/$(IMAGE_REPOSITORY):kkk
displayName: 'Build and push docker image'
env:
REGISTRY_PASSWORD: $(REGISTRY_PASSWORD)
my Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . /src
RUN dotnet restore ./Project.Api/Project.Api.csproj
RUN dotnet publish ./Project.Api/Project.Api.csproj --no-restore -c Release -o /app
FROM build AS publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Project.Api.dll"]
Does anyone know that is the cause of this error and how to fix it? Thank you.
Follow standard troubleshooting steps: Check what directory you're running that bash command out of. Put a RUN ls or similar command in your Dockerfile so you can check the directory structure within your container during build and confirm it's what you expect.
Your Docker context is likely set a directory level higher than you think it is.
You can set your working directory appropriately from there.
- bash: |
docker ..
workingDirectory: $(build.sourcesDirectory)/src
I'd guess that your code is ending up in the directory /src/src/ in your Dockerfile.
Currently, I have app (.Net Core 3.1) which is listening on port 40003. Now I'm trying to put it into a container. I created dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 40003
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["myProject/myProject/myProject.csproj", "myProject/myProject/"]
RUN dotnet restore "myProject/myProject/myProject.csproj" --configfile ./NuGet.Config
COPY . .
WORKDIR "/src/myProject/myProject"
RUN dotnet build "myProject.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "myProject.csproj" -c Release -o /app/publish
FROM base AS final
ENV ASPNETCORE_URLS=http://*:40003
ENV ASPNETCORE_ENVIRONMENT="development"
EXPOSE 40003
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "myProject.dll"]
As you see I exposed port 40003 and set variable ASPNETCORE_URLS.
I run it:
docker run -it --rm --name myTag -p 40003:40003 myTag
When I log into container:
docker exec -it myTag bash
and executing:
wget http://localhost:40003
I got the expected result. So I believe that my component inside the container is alive and listening
However when I am trying to go to
http://localhost:40003
from my local browser, I'm receiving ERR_EMPTY_RESPONSE.
Can you give some advice? Thank you in advance.
Edit:===================
I posted a complete docker file. (added first 3 lines to docker file which defines base).
Yes I'm sure that I posted to HTTP (not https).
http://localhost:40003 returns correct response which is a custom "selftest"
On not development env this endpoint is blocked. Something like:
[HttpGet]
[HttpPost]
public JsonResult<DiagnosticsResult> ServerStatus()
The response: I really got no response. No 200, 404 etc. simple nothing.
Also I'm logging now that result of self tests. Above when I'm inside the docker
INFORMATION 2021-11-30 09:15:48,738 [Omdc.SelfHost.Base.Tests.MinimumDiskSpaceTest.Run] MinimumDiskSpaceTest starting.
INFORMATION 2021-11-30 09:15:48,741 [Omdc.SelfHost.Base.Tests.MinimumDiskSpaceTest.Run] Drive: /, Volume label: /, Total available space: 82%
But when I'm requesting from a local browser there are neither console logs nor HTTP responses.
So my request to not reach the endpoint (?)
I have a simple API which I am running in Docker
When I run the command to run my image I get the output below
PS C:\Users\harili\GoodFood-backend> docker run -p 8080:80 --name container-backend-goodfood image-backend-goodfood
{"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 {f3c716ee-bcbe-4357-ba6e-3fcdbb6b9817} may be persisted to storage in unencrypted form.","State":{"Message":"No XML encryptor configured. Key {f3c716ee-bcbe-4357-ba6e-3fcdbb6b9817} may be persisted to storage in unencrypted form.","KeyId":"f3c716ee-bcbe-4357-ba6e-3fcdbb6b9817","{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: /app","State":{"Message":"Content root path: /app","contentRoot":"/app","{OriginalFormat}":"Content root path: {contentRoot}"}}
However, I get connection refused when using Postman (even on browser)
http://localhost:8080/api/v1/Authentication/test (it's a get http request)
public IActionResult Test()
{
return Ok(new { Test = "it works test"});
}
Any idea what is wrong?
My docker file is:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["GoodFood.Api/GoodFood.Api.csproj", "GoodFood.Api/"]
COPY ["GoodFood.Library/GoodFood.Library.csproj", "GoodFood.Library/"]
RUN dotnet restore "GoodFood.Api/GoodFood.Api.csproj"
COPY . .
WORKDIR "/src/GoodFood.Api"
RUN dotnet build "GoodFood.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "GoodFood.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "GoodFood.Api.dll"]
As you can see I am exposing port 80 above
There the command I use to run my container :
docker run -p 8080:80 --name container-backend image-backend
I started a docker container with an ASP.NET app inside. The logs say that the application started successfully and is alive, but when I try to access the home page of the app I get the ERR_EMPTY_RESPONSE and the error page of the browser.
Here is my dockerfile:
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
COPY /bin/Debug/net5.0/ App/
WORKDIR /App
ENTRYPOINT ["dotnet", "TritaniumLocal.Web.Host.dll"]
Here is my docker build command: docker build -t "tritaniumlocal" .
Here is my docker run command: docker run -d -p 44311:44311 tritaniumlocal aspnetapp2.
The app starts from Visual Studio on port 44311. I tried also without port remap, but nothing helped
UPD: Here is a part of a log which can help:
warn: Microsoft.AspNetCore.Server.Kestrel[0] Unable to bind to http://localhost:44311 on the IPv6 loopback interface: 'Cannot assign requested address'. Hosting environment: Production Content root path: /App Now listening on: http://localhost:44311 Application started. Press Ctrl+C to shut down.
I'm attempting to run a asp.net core application from a raspberry pi using docker, I think I have the main parts down. I have a repository on github that is a simplistic asp.net core project. I have setup an account on docker cloud which build everytime I push to my github repo.
I have docker pulled my repository onto my pi:
I run the command:
docker run -d -p 8080:80 joro550/radiusnet --network=host
and I can see that it is running:
But when I go to my pi's ip address on port 8080 then I get this:
When I've been searching around for this people have suggested adding these flags (which I have tried and come up with the same results:
adding --network=host to the docker run command
adding -it to the docker run command
Adding Expose 80 into the docker file
I think at this point I'm at a bit of a lose as to how to access this thing.
The docker documentation does suggest running
`docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" myapp`
If I'm using windows 10 Nano containers, which I don't believe I'm using but when I run this command I get a resounding <no value>
Cutting it back to docker inspect -f "{{ .NetworkSettings.IPAddress }}" myapp gives me a different ip address to my ips internal ip address, which I've tried on port 8080 and get the same result
Doing a curl on both addresses gives me the same result of connection refused:
Here's my docker file for anyone interested:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY /src ./
RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out -r linux-arm
# build runtime image
FROM microsoft/dotnet:2.0.0-runtime-stretch-arm32v7
WORKDIR /app
COPY --from=build-env /app/src/RadiusNet.Web/out .
EXPOSE 80
ENTRYPOINT ["dotnet", "RadiusNet.Web.dll"]
If any more information is needed please ask, I'm pretty new to Docker so I just did a bit of a knowledge dump of my current situation.
Link to github project (if it's needed): https://github.com/joro550/RadiusNet
Any help - at this point will be greatly appreciated
Cutting it back to docker inspect -f "{{ .NetworkSettings.IPAddress }}" myapp gives me a different ip address to my ips internal ip address, which I've tried on port 8080 and get the same result
Try curling the port 5000 and 80 with this IP address from inside the raspbery pi rather than 8080. Plus, are you sure you are exposing the right port? You have "expose 80" but the port 8080 is mapped to 5000, and docker ps shows no mapping for 80