How do i allow my docker container to connect to local stack

Viewed 1031

OS : mac Os Big sur

Hi i wanted to connect to local stack running on 4566 in test-network from another docker container also running in test-network.

From inside the docker container if i run:

aws --endpoint-url=http://localhost:4566 dynamodb list-tables

Could not connect to the endpoint URL: "http://localhost:4566/"

Outside the docker container if i run :

 aws --endpoint-url=http://localhost:4566 dynamodb list-tables
{
    "TableNames": [
        "test-table-1"
    ]
}

Any help will be appreciated

1 Answers

If you are using docker-compose to define your localstack image, and you haven't changed away from the default networking mode, then you will need to use the name of the service when interacting with localstack from within any of the containers.

The default networking mode creates a bridge network that is shared by all services running on the same machine. Those services are discoverable by each other based on the bridge that Docker sets up.

Assuming that your service is called localstack, then you would need to set your AWS endpoint to http://localstack:4566. If your localstack service was called my-localstack and you changed the port to 4080, then you would use http://my-localstack:4080.

See this semi-related answer

Related