DevContainers
Overview
Section titled “Overview”DevContainers let you define a self-contained, reproducible and containerized development environment for your project.
LocalStack publishes two building blocks for DevContainers:
- LocalStack Templates: complete DevContainer setups that run LocalStack next to your code.
- LocalStack Feature: installs
lstk, the LocalStack CLI, into any DevContainer.
Both install lstk.
lstk replaces the deprecated localstack CLI and the awslocal, tflocal, cdklocal and samlocal wrapper scripts.
Version 0.x of the Feature and Templates installed the deprecated CLI. See Migrating from 0.x.
Prerequisites
Section titled “Prerequisites”- A supporting tool, such as the Dev Container CLI or VS Code with the Dev Containers extension.
- Docker.
- A LocalStack auth token, exported as
LOCALSTACK_AUTH_TOKENon the host. The Templates read it from the host environment and never write it into your files.
LocalStack Templates
Section titled “LocalStack Templates”LocalStack provides two Templates.
| Type | Advantages | Disadvantages |
|---|---|---|
Docker-in-Docker (localstack-dind) |
• Strict separation from the host Docker daemon • lstk starts, stops and restarts LocalStack• All-in-one container |
• LocalStack and the containers it starts share the dev container’s resources • Larger container • Cannot reuse images from the host |
Docker-outside-of-Docker (localstack-dood) |
• Add more services in Docker Compose • LocalStack’s DNS server resolves localhost.localstack.cloud and custom domains in the dev container |
• The host’s Docker socket is mounted into containers • Docker Compose, not lstk, controls the LocalStack container |
Template options
Section titled “Template options”| Option | Templates | Default | Description |
|---|---|---|---|
imageVariant |
Both | noble |
Ubuntu or Debian version of the base image (noble, jammy, resolute or bookworm). |
version |
Both | latest |
Tag of the localstack/localstack-pro image, for example stable or 2026.10. |
logLevel |
Both | info |
LocalStack log level (LS_LOG). |
debug |
Both | false |
Debug mode (DEBUG). |
persistence |
Both | false |
Keep state across restarts (PERSISTENCE). |
enforceIam |
Both | false |
Enforce IAM policies (ENFORCE_IAM). |
loadPods |
Both | empty | Cloud Pods to load at start-up, comma-separated (AUTO_LOAD_POD). |
defaultRegion |
Both | us-east-1 |
Default region for the AWS CLI and SDKs in the dev container. |
startup |
DinD | true |
Run lstk start when the dev container starts. |
networkName |
DooD | ls |
Docker network shared by LocalStack, the dev container and Lambda containers. |
networkCidr |
DooD | 10.0.2.0/24 |
Subnet of that network. |
ipAddress |
DooD | 10.0.2.20 |
IP address of the LocalStack container, inside networkCidr. |
host |
DooD | localhost.localstack.cloud:4566 |
Hostname and port LocalStack advertises (LOCALSTACK_HOST). |
volumePath |
DooD | ./.volume |
Host folder for LocalStack state, relative to .devcontainer/. |
For other LocalStack variables, see the configuration reference.
Docker-in-Docker
Section titled “Docker-in-Docker”LocalStack runs in the dev container’s own Docker daemon.
lstk start runs on every container start and returns when LocalStack is ready.
Dev Container CLI
Section titled “Dev Container CLI”Create a JSON file called options.json with the options you want to change:
{ "imageVariant": "noble", "logLevel": "debug", "debug": "true"}Generate the .devcontainer folder from the Template.
Add Features for the tools you use with the --features option, for example Terraform for lstk terraform:
devcontainer templates apply \ --template-id ghcr.io/localstack/devcontainer-template/localstack-dind \ --template-args "$(cat ./options.json)" \ --features '[{"id":"ghcr.io/devcontainers/features/terraform:1"}]'Start the container and open a shell in it:
devcontainer up --id-label project=localstack --workspace-folder .devcontainer exec --id-label project=localstack /bin/bashCheck that LocalStack is running:
lstk statusThe Dev Container CLI cannot remove containers yet. Remove it with Docker:
docker rm -f $(docker ps -aq --filter label=project=localstack)Reference files
Section titled “Reference files”The Template creates the following files:
{ "name": "LocalStack DinD setup", "image": "mcr.microsoft.com/devcontainers/base:noble", "remoteEnv": { "LOCALSTACK_AUTH_TOKEN": "${localEnv:LOCALSTACK_AUTH_TOKEN}", "AWS_REGION": "us-east-1", "AWS_DEFAULT_REGION": "us-east-1", "AWS_PROFILE": "localstack" }, "features": { "ghcr.io/devcontainers/features/docker-in-docker:4": {}, "ghcr.io/devcontainers/features/aws-cli:1": {}, "ghcr.io/localstack/devcontainer-feature/localstack-cli:1": {} }, "postCreateCommand": "bash .devcontainer/lstk/post-create.sh", "postStartCommand": "bash .devcontainer/lstk/post-start.sh true", "mounts": [ { "source": "localstack-data-${devcontainerId}", "target": "/data", "type": "volume" } ]}[[containers]]type = "aws"tag = "latest"port = "4566"volumes = ["/data:/var/lib/localstack"]env = ["devcontainer"]
[env.devcontainer]DEBUG = "false"LS_LOG = "info"PERSISTENCE = "false"ENFORCE_IAM = "false"AUTO_LOAD_POD = ""post-create.sh links ~/.config/lstk/config.toml to .devcontainer/lstk/config.toml, so every lstk command in the container uses it.
It also runs lstk setup aws to write the localstack AWS profile.
post-start.sh waits for Docker and runs lstk start.
To change LocalStack settings, edit .devcontainer/lstk/config.toml and run lstk restart.
See the lstk configuration reference.
LocalStack state is stored in a Docker volume mounted at /data, so it survives container rebuilds.
Docker-outside-of-Docker
Section titled “Docker-outside-of-Docker”LocalStack runs as the localstack service in Docker Compose, on the host’s Docker daemon.
The dev container and LocalStack share a Docker network.
LocalStack’s DNS server resolves localhost.localstack.cloud to the LocalStack container, and Lambda containers join the same network through LAMBDA_DOCKER_NETWORK.
Dev Container CLI
Section titled “Dev Container CLI”Create a JSON file called options.json with the options you want to change:
{ "imageVariant": "bookworm", "logLevel": "debug", "debug": "true", "networkName": "localstack-network", "networkCidr": "192.168.9.0/24", "ipAddress": "192.168.9.13"}Generate the .devcontainer folder from the Template:
devcontainer templates apply \ --template-id ghcr.io/localstack/devcontainer-template/localstack-dood \ --template-args "$(cat ./options.json)"Start the container and open a shell in it:
devcontainer up --id-label project=localstack --workspace-folder .devcontainer exec --id-label project=localstack /bin/bashCheck that lstk reaches LocalStack:
lstk statusTo remove the containers and the network, run:
docker compose \ --project-name "$(basename $PWD)_devcontainer" \ -f ./.devcontainer/docker-compose.yml downReference files
Section titled “Reference files”{ "name": "LocalStack DooD setup", "dockerComposeFile": "docker-compose.yml", "service": "app", "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", "features": { "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, "ghcr.io/devcontainers/features/aws-cli:1": {}, "ghcr.io/localstack/devcontainer-feature/localstack-cli:1": {} }, "postCreateCommand": "lstk --non-interactive setup aws --force", "postStartCommand": "bash .devcontainer/lstk/post-start.sh"}services: localstack: container_name: localstack-main image: localstack/localstack-pro:latest ports: - "127.0.0.1:4566:4566" # LocalStack Gateway - "127.0.0.1:4510-4559:4510-4559" # External services port range - "127.0.0.1:443:443" # LocalStack HTTPS Gateway env_file: - .env environment: LOCALSTACK_AUTH_TOKEN: ${LOCALSTACK_AUTH_TOKEN:-} LAMBDA_DOCKER_NETWORK: ls volumes: - "/var/run/docker.sock:/var/run/docker.sock" - "./.volume:/var/lib/localstack" networks: ls: ipv4_address: 10.0.2.20
app: build: context: . dockerfile: Dockerfile volumes: - ../..:/workspaces:cached command: sleep infinity init: true environment: LOCALSTACK_AUTH_TOKEN: ${LOCALSTACK_AUTH_TOKEN:-} LSTK_ENDPOINT_URL: http://localhost.localstack.cloud:4566 LOCALSTACK_HOST: localhost.localstack.cloud:4566 AWS_PROFILE: localstack AWS_REGION: us-east-1 AWS_DEFAULT_REGION: us-east-1 dns: - 10.0.2.20 depends_on: - localstack networks: - ls
networks: ls: name: ls ipam: config: - subnet: 10.0.2.0/24DEBUG=falseLS_LOG=infoPERSISTENCE=falseENFORCE_IAM=falseAUTO_LOAD_POD=LOCALSTACK_HOST=localhost.localstack.cloud:4566FROM mcr.microsoft.com/devcontainers/base:nobleLSTK_ENDPOINT_URL points lstk at the localstack service.
lstk status, lstk aws, lstk terraform, lstk cdk, lstk sam and the snapshot commands work as usual.
lstk start, lstk stop, lstk restart and lstk logs refuse to run against an external endpoint.
Use docker restart localstack-main and docker logs localstack-main instead.
See Targeting an external emulator.
To change LocalStack settings, edit .devcontainer/.env and rebuild the container.
VS Code
Section titled “VS Code”To add a Template in VS Code:
-
Open the Command Palette and select Dev Containers: Add Dev Container Configuration Files….

-
Select Add configuration to workspace, or Add configuration to user data folder for general use.

-
Select Show All Definitions… to list community Templates.

-
Type
localstackand select LocalStack Docker-in-Docker or LocalStack Docker-outside-of-Docker.
-
Accept or change the Template options. Pressing Enter through all of them gives a working setup.
-
Optionally add more Features, such as Terraform, Node.js and AWS CDK, or the AWS SAM CLI.

-
Run Dev Containers: Reopen in Container.
Using LocalStack in the container
Section titled “Using LocalStack in the container”Both Templates write a localstack AWS profile and set AWS_PROFILE=localstack, so the AWS CLI and the AWS SDKs target LocalStack without extra configuration:
lstk aws s3 mb s3://my-bucketaws s3 lsUse the lstk proxies for infrastructure-as-code tools.
They need the tool itself, so add its Feature to devcontainer.json:
| Command | Replaces | Feature for the tool |
|---|---|---|
lstk aws |
awslocal |
ghcr.io/devcontainers/features/aws-cli:1 (added by both Templates) |
lstk terraform |
tflocal |
ghcr.io/devcontainers/features/terraform:1 |
lstk cdk |
cdklocal |
ghcr.io/devcontainers/features/node:1 and ghcr.io/devcontainers-extra/features/aws-cdk:2 |
lstk sam |
samlocal |
ghcr.io/customink/codespaces-features/sam-cli:1 |
For Pulumi, set the Feature’s pulumilocal option to install the pulumilocal wrapper, and add ghcr.io/devcontainers-extra/features/pulumi:1.
LocalStack Feature
Section titled “LocalStack Feature”Add the Feature to any DevContainer to install lstk:
"features": { "ghcr.io/localstack/devcontainer-feature/localstack-cli:1": {}}| Option | Default | Description |
|---|---|---|
version |
latest |
lstk release to install, for example 1.5.0. |
pulumilocal |
false |
Install the pulumilocal wrapper with pipx. |
The Feature installs lstk with its shell completions and man pages on Debian, Ubuntu and Alpine images.
To start LocalStack, lstk also needs Docker, for example from the docker-in-docker Feature, and an auth token:
"remoteEnv": { "LOCALSTACK_AUTH_TOKEN": "${localEnv:LOCALSTACK_AUTH_TOKEN}"}You can also run lstk login in a terminal in the container.
Migrating from 0.x
Section titled “Migrating from 0.x”Version 1.0.0 of the Feature and Templates replaces the deprecated localstack CLI with lstk.
- The Feature options
awslocal,cdklocal,samlocal,tflocalandinstallUsingPythonare removed. Use thelstkproxies instead. - The Template options
awslocal,cdklocal,pulumilocal,samlocal,tflocalanduseProare removed. The Docker-in-Docker Template also dropsvolumePath, as state now lives in a Docker volume. - The Templates no longer set
AWS_ENDPOINT_URLorLOCALSTACK_API_KEY.
To keep using the deprecated CLI, pin the old Feature version, ghcr.io/localstack/devcontainer-feature/localstack-cli:0.
See the lstk migration guide for the command mapping.