I am building a microservice solution using docker compose to run locally. I'm using .netcore for the services. When I run the projects using visual studio everything connects and works fine but when i run in docker i can connect to the services externally but the services are unable to connect to each other.When I inspect in docker everything looks ok and all containers are on the same network. I'm assuming it is some small setting or configuration I'm missing but haven't been able to find anyone with the same issue.
Here's the docker-compose code
docker-compose.yml
version: '3'
services:
underrule.frontend:
image: underrule.frontend
build:
context: ./UnderRule.FrontEnd
dockerfile: Dockerfile
underrule.apigateway:
image: underrule.apigateway
build:
context: ./UnderRule.ApiGateway
dockerfile: Dockerfile
underrule.authentication:
image: underrule.authentication
build:
context: ./UnderRule.Authentication
dockerfile: Dockerfile
underrule.playerservice:
image: underrule.playerservice
build:
context: ./UnderRule.PlayerService
dockerfile: Dockerfile
underrule.registrationservice:
image: underrule.registrationservice
build:
context: ./UnderRule.RegistrationService
dockerfile: Dockerfile
underrule.worldservice:
image: underrule.worldservice
build:
context: ./UnderRule.WorldService
dockerfile: Dockerfile
docker-compose.override.yml
version: '3'
services:
underrule.frontend:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5000:80"
underrule.apigateway:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "9000:80"
underrule.authentication:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5001:80"
underrule.playerservice:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5002:80"
underrule.registrationservice:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5004:80"
underrule.worldservice:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "5003:80"
all dockerfiles are basically the same
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "UnderRule.ApiGateway.dll"]
Any ideas? I've tried messing with the ports without much luck.
I am connecting internally using HttpClient with the path like http://localhost :{port}
Help is very much appreciated and let me know if you need more info.
Within a container, localhost points to the container itself and not the bridged network.
As you are using docker-compose, you should point to the container name defined in docker-compose.yml file (eg underrule.worldservice -> http://underrule.worldservice:port ).
Another way is to point to the docker bridge network ip. On linux this IP is by default 172.17.0.1. On windows it depends on the version of docker you are running you should inspect your configuration ( ipconfig
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.