Local machine refuses to connect to an ASP.NET Core Web API container
Hello
I need to find out how to access my Docker container via the host machine. My connection is refused, no matter the tool I use (browser,
curl
, wget
, javascript's fetch
). I've been looking for a solution since yesterday, but no success at all.
I've been trying to instantiate two containers within a same docker network, which is basically an ASP.NET Core Web API and a PostgreSQL server.
I have 0 Docker knowledge at all. I was using Rider's feature for instantiating containers and it worked properly. However, I decided to use a docker-compose.yml
file instead, because I was editing the same environment variables in both containers (such as PostgreSQL credentials and a default user seed data). I've deleted the IDE configuration before I actually start to build the docker-compose.yml
file as follows:
Both containers run properly, I just can't connect to the api container externally.7 Replies
Source Code
this is the API source code: https://github.com/trsaints/trsaints-frontend-api
The api container's http port is mapping to 8082 becaues I have an apache server running on the host's 8080 port. But that shouldn't be an issue at all, as far as I know.
What I've tried until then
Also, I've tried the following suggestions from forum posts with related issues:
* Checking
iptables
rules to assure the container address is not being blocked by the host's firewall:
sudo iptables -L -v -n | grep 808
:
* Disabling ufw
temporarily
* Setting ASPNETCORE_URLS
to http://+:8080/
* Adding Kestrel:EndPoints:Http:Url=http://+:8080
to docker-compose.yml
* Delete the container's and its images to clear any previous data
None of the options above had any effect.no effect ;/
try adding
Kestrel:EndPoints:Http:Url=http://+:8080
in the docker-compose file? no effect at all
Docker networking
docker network inspect
for that docker-compose
network is as follows. I just removed the MacAddress
parts for security reasons:
As the output suggests, the container's address is 172.18.0.3
, but any tool that attempts to connect externally just gets refused and fails
Actually, I've tried to run busybox
and appropriate
images for fetching data inside the network, but looks like the response is the same:
So you can confirm with the docker logs that the server is running?
so, it was actually an IDE thing. Running the containers using the IDE's UI would actually set the environment to development and enable Swagger, for example
I found out that the environment was set to
Production
after some debugging
I had to explicitly add an ASPNETCORE_ENVIRONMENT
to the docker-compose.yml
file
thank you all for checking the post, btw