0

I've got two docker containers running as part of a docker-compose file, ContainerA is localstack where I'm running a lambda function which is trying to make a HTTP POST request to ContainerB using the below simplified code:

var content = new StringContent("{ "content": "sample" }", Encoding.UTF8, "application/json");
var httpClient = new HttpClient();
var response = await HttpClient.PostAsync("http://ContainerB/Foo", content);

Which raises the following exception:

Request failed - System.Net.Http.HttpRequestException: Name or service not known

If I make the same request from the console of Container A this request succeeds e.g.

curl http://ContainerB/Foo -H "Content-Type: application/json" -d "{ "content": "sample" }"

As this request succeeds from the console I'm fairly confident that it's not a networking issue between my docker containers.

0

1 Answer 1

0

Localstack lambda's are created in a new Docker container per execution, this continer is outside of the docker-compose stack and therefore it is not a part of the docker-compose default network. See this GitHub issue for more information.

In order to work around this, you must first create an external bridge network within docker:

docker network create -d bridge MyNetwork

And then connect each docker container to it within your docker compose file and register this as an external network:

services:
  localstack:
    networks:
      - MyNetwork
  ...
  ...

networks:
  MyNetwork:
    external: true
Sign up to request clarification or add additional context in comments.

Comments

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.