I am trying to connect to my GraphQL API in a docker container, but I am not able to reach it in Postman nor a web browser.
My dockerfile and docker compose file might have a problem, but I am not sure what is broken.
In my docker image file I am exposing ports:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
And in my docker-compose file (network is included due to another container):
version: '2'
networks:
default:
ipam:
driver: default
services:
app:
image: graphql
volumes:
- ../:/https/
env_file:
- ../env.secrets
ports:
- "5000:5000"
- "5001:5001"
networks:
- default
My appsettings.json file:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Urls": "http://*;https://*"
}
If I run my app outside docker and use postman I can access my GraphQL endpoint without any problems and do my queries: 'http://localhost:5000/graphql'
However that is not the case when I run it inside a container. I am sure my ports are configured correctly.
If I run docker container ls I see the following, which looks right:
I got it working in Postman. I changed my ports accordingly:
5000-5001/tcp, 0.0.0.0:5000->80/tcp
So my port mapping in my compose file is changed to:
services:
app5:
image: graphql-app5-demo
volumes:
- ../:/https/
env_file:
- ../env.secrets
ports:
- 5000:80
networks:
- default
And my postman endpoind URL: "http://localhost:5000/graphql"
Although I really wants to not use port 80 here, but rather use the same port as 5000.