Reputation: 21088
How can I make a request from one docker container to another using the docker network and two different docker-compose files which contain the container settings?
I've a simple web api that should be called using this console application. The web api is hosted using the following docker compose file:
version: '3.5'
services:
webapi_test:
image: ${DOCKER_REGISTRY-}webapi_test
build:
context: .
dockerfile: webapi_test/Dockerfile
links:
- mongo
networks:
- sample_network
mongo:
image: mongo:latest
container_name: "mongodb"
ports:
- "27017:27017"
command: mongod --smallfiles --logpath=/dev/null # --quiet
networks:
- sample_network
networks:
sample_network:
name: sample_network
The web api should be called using this simple console application:
class Program
{
static void Main(string[] args)
{
var url = "https://webapi_test:44334/api/Role";
var client = new HttpClient();
var result = client.GetStringAsync(url).Result;
Console.WriteLine($"Result: {result}");
}
}
Docker compose of the console application:
version: '3.5'
services:
networksample:
image: ${DOCKER_REGISTRY-}networksample
build:
context: .
dockerfile: NetworkSample/Dockerfile
networks:
- sample_network
networks:
simplic_network:
name: sample_network
The communication should be done in the local docker network as far as I know. But I always get the following error message in the console application: SocketException: Resource temporarily unavailable
The web api is available from outside: https://localhost:44334/api/Role
...
EDIT I just have one docker host.
Upvotes: 0
Views: 2904
Reputation: 11544
make sample_network
as external network:
version: '3.5'
services:
networksample:
image: ${DOCKER_REGISTRY-}networksample
build:
context: .
dockerfile: NetworkSample/Dockerfile
networks:
- sample_network
networks:
simplic_network:
external:
name: sample_network
Upvotes: 1
Reputation: 12089
Seems like a SSL issue, try to replace https
with http
in var url = "https://webapi_test:44334/api/Role";
Upvotes: 3