0

I'm new to docker and I'm trying to run a simple ASP.NET Core 6 application on a docker container on Ubuntu, but, I'm getting the HTTP ERROR 404 error when I try to access the appication via Google Chrome.

This is my Dockerfile:
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
    
# 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
    
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "TesteDocker.dll"]

I have disabled the HTTPS redirection on Program.cs

I'm using this commands to build the image and run the container:

docker build -t testedocker .
docker run -d -p 5000:5000 --name testedocker_container testedocker

And trying to access the app URL in this way: http://localhost:5000/swagger

What I'm doing wrong?

1
  • check docker logs on which port ASP.NET core app is running inside container. in dockerfile you have exposed 5000 but in mapping you have given 80. you have to map to port on which it is running inside the container. Commented Oct 17, 2022 at 5:34

1 Answer 1

6

Swagger is, by default, only available when the app is run in development mode. Docker is, by default, not development mode.

To make it run in development mode, you can set the ASPNETCORE_ENVIRONMENT environment variable to 'Development' when you run the container, like this

docker run -d -p 5000:80 -e ASPNETCORE_ENVIRONMENT=Development --name testedocker_container testedocker

Then you should be able to access the swagger pages.

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

4 Comments

It doens't work, now I'm receiving the ERR_CONNECTION_RESET error
Stoping and removing the container and running the command again, without specifing the ASPNETCORE_ENVIRONMENT variable, and then trying to access an action on my controller instead of swagger doens't work too
I just noticed that your app listens on port 5000. Then you need to map to port 5000 rather than 80 by using -p 5000:5000 rather than -p 5000:80.
Sorry, I'm mapping to 5000, but when I make the question I put the wrong docker run command (that I have copied from the docker website as reference when I started), I have edited my post.

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.