0

It's my first time using Docker and im trying to run an image but i need it to work on the port 4242, but when i write the command sudo docker run -it --rm -p 4242:5001 docker-project:v1 and when i go to https://localhost:4242/weatherforecast with my launcher i have nothing, it keeps working with the port 5001 and i want it to work in the port 4242.

There is my docker file if it can help

FROM mcr.microsoft.com/dotnet/aspnet:3.1-focal AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5001
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:3.1-focal AS build
WORKDIR /src
COPY ["dockerProject.csproj", "./"]
RUN dotnet restore "dockerProject.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "dockerProject.csproj" -c Release -o /app/buil
FROM build AS publish
RUN dotnet publish "dockerProject.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "dockerProject.dll"]
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • In your dockerfile, you are using `EXPOSE 5000`. From your question , i understand that you want to expose the port 5001 – Nabil Jan 12 '22 at 22:43

1 Answers1

0

You set ASPNETCORE_URLS to http://+:5001 meaning that your app will use http. So when you go to https://localhost:4242/weatherforecast, it won't work because the communication isn't encrypted.

Use http://localhost:4242/weatherforecast instead.

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • I did what u told me but it keeps telling me " localhost does not allow the connection." –  Jan 13 '22 at 00:03
  • In the logs that are output when you start the container, can you check that it says that it's listening on port 5001? – Hans Kilian Jan 13 '22 at 06:39
  • Yeah, it says its listening on port 5000 even if there is no 5000 in my code –  Jan 13 '22 at 11:56
  • @Elies Very strange and I don't understand why. But try changing your docker run parameter to `-p 4242:5000` and then going to http://localhost:4242/ – Hans Kilian Jan 13 '22 at 12:55