2

I followed a tutorial about creating a web-app using Docker. My dockerfile exposes port 5000:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 5000
#EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR .
COPY ["CustomerApi/CustomerApi.csproj", "CustomerApi/"]
COPY ["CustomerApi.Domain/CustomerApi.Domain.csproj", "CustomerApi.Domain/"]
COPY ["CustomerApi.Service/CustomerApi.Service.csproj", "CustomerApi.Service/"]
COPY ["CustomerApi.Data/CustomerApi.Data.csproj", "CustomerApi.Data/"]
RUN dotnet restore "CustomerApi/CustomerApi.csproj"
COPY . .
WORKDIR "./CustomerApi"
RUN dotnet build "CustomerApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "CustomerApi.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CustomerApi.dll"]

when I run the image locally using

docker run myrepo/demo:latest -p 5000:5000 -p 5001:5001 -e ASPNETCORE_HTTP_PORT=https://+:5001 -e ASPNETCORE_URLS=http://+:5000

and open my browser on https://localhost:5000 I get ERR_EMPTY_RESPONSE (I'm not sure why I need 5001 within my docker run-command at all, as it's not exposed within my dockerfile).

When I inspect the image within docker desktop I see this:

enter image description here

In particular it shows ASPNETCORE_URLS=http://+80, although I overwrote that above using -e ASPENTCORE_URLS=https://5000.

1 Answer 1

3

The options on docker run are split up in 2 parts:

  • Options before the image name are docker options
  • Options after the image name override any CMD and is sent to the container

So your command should look like this

docker run -p 5000:5000 -p 5001:5001 -e ASPNETCORE_HTTP_PORT=https://+:5001 -e ASPNETCORE_URLS=http://+:5000 myrepo/demo:latest

EXPOSE doesn't actually do anything. It's mostly documentation about what ports you think the container uses. It can be wrong and if it's wrong you don't get any errors or warnings.

Sign up to request clarification or add additional context in comments.

4 Comments

haha, that is ridiculously simple. I'd never thought the order of params had any effect. Thank you for your anser, it works.
I still don't get the point for that 5001-port, as it also returns ERR_EMPTY_RESPONSE for both http and https. I assume I don't need it
I think the correct environment variable name is ASPNETCORE_HTTPS_PORT (with an 'S'). So yours probably does nothing. If I want both http and https, I only use ASPNETCORE_URLS and set it to https://+:5001;http://+:5000.
hmmm, no ASPNETCORE_HTTPS_PORT seems to be an invalid variable. And I wasn't able to set ASPNETCORE_URLS=https://+:5001;http://+:5000 (""docker run" requires at least 1 argument."). I also tried to set the value into quotes. But I leave that for another question, thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.