LocalStack Docker Network Setup¶
This guide outlines the necessary network configuration to enable communication between a LocalStack container and the [[AWS CLI]] or other client tools running in separate Docker containers.
Network Creation¶
To facilitate communication between containers, a dedicated Docker network named localstack must be created on the host machine^[demo-terraform-localstack__README.md].
docker network create localstack^[demo-terraform-localstack__README.md]
LocalStack Configuration¶
Once the network is created, the LocalStack container (usually managed via docker-compose) must be configured to join this network^[demo-terraform-localstack__README.md]. This is achieved by modifying the docker-compose.yml file to use the externally created network^[demo-terraform-localstack__README.md].
networks:
default:
external:
name: "localstack"^[demo-terraform-localstack__README.md]
Client Container Connection¶
Client tools, such as the official AWS CLI v2 running in a Docker container, must be attached to this same network to interact with the LocalStack instance^[demo-terraform-localstack__README.md]. When executing the CLI container, use the --network flag to specify the network and the --endpoint-url flag to point to the LocalStack service DNS name^[demo-terraform-localstack__README.md].
docker run --network localstack --rm -it amazon/aws-cli --endpoint-url=http://localstack:4566 <COMMAND>^[demo-terraform-localstack__README.md]
Usage Convenience¶
For frequent interactions, it is convenient to create a shell alias that wraps the Docker run command with the necessary network, volume, and endpoint configurations^[demo-terraform-localstack__README.md].
alias laws='docker run --network localstack -it -v ~/.aws:/root/.aws -e LOCALSTACK_HOSTNAME=localstack amazon/aws-cli --endpoint-url=http://localstack:4566'^[demo-terraform-localstack__README.md]
Related Concepts¶
- [[LocalStack]]
- Docker Compose
- Terraform