Configuring Localstack with Docker Compose - shadowhand/blog GitHub Wiki
Last updated: 2023-11-16
The Localstack Docker Compose example is incomplete if you have other
Docker containers that need to communicate with Localstack. The trick is to create a network alias
for localhost.localstack.cloud
(which normally points to 127.0.0.1
):
version: "3.8"
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME-localstack-main}"
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
- DEBUG=${DEBUG-}
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
default:
aliases:
- localhost.localstack.cloud
Note the last networks
section, which is not in the Localstack example. This leverages the
network aliases to point network access to localhost.localstack.cloud
to the localstack
service container.