0

I have created a ASP.NET Core Web API app with Docker enabled just using the auto generated boilerplate code. Running on Docker on my Windows dev machine works just fine. But when I deploy the app to Docker running on Ubuntu, I'm not able to connect to the API. Doing a Docker ps shows that it is listening on port 8098 on the host. It is connected to the docker_default, just as my other containers which works. The port mapping, using docker -ps for the container is

 0.0.0.0:8098->8080/tcp, :::8098->8080/tcp 

Looking at the container logs, it listens to the 8080-port in the container:

  Info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://[::]:8080

But when trying to connect to port 8098 I just get a 404. As far as I can tell, everything looks like it should, but it does just not work. Any suggestions on what to try next?

1 Answer 1

0

404 can only come from the service, so you are able to connect successfully. I'll take a guess that you're trying to access the Swagger pages. Swagger is only available when the application runs in development mode (see Program.cs for the if statement that causes this). The default environment for a container is not development.

To tell your application that you're running in development mode, add -e ASPNETCORE_ENVIRONMENT=Development as an option to your docker run command. Remember to place the option before the image name in the command. Something like this

docker run -p 8098:8080 -e ASPNETCORE_ENVIRONMENT=Development -d myimage

Then Swagger will be available.

If that doesn't help, then please edit your question and add

  • the command you use to run your container
  • the URL you're trying to access

Without setting the environment variable, you should still be able to access the actual API on http://localhost:8098/weatherforecast. It's only Swagger that's disabled.

All this, ofc, assumes that my guess that you're trying to access Swagger is correct :)

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

1 Comment

Thanks Hans! That was the issue! Now I feel rather stupid... :)

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.