Skip to content
Get Started for Free

DevContainers

DevContainers let you define a self-contained, reproducible and containerized development environment for your project.

LocalStack publishes two building blocks for DevContainers:

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.

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
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.

LocalStack runs in the dev container’s own Docker daemon. lstk start runs on every container start and returns when LocalStack is ready.

Create a JSON file called options.json with the options you want to change:

options.json
{
"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:

Terminal window
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:

Terminal window
devcontainer up --id-label project=localstack --workspace-folder .
devcontainer exec --id-label project=localstack /bin/bash

Check that LocalStack is running:

Terminal window
lstk status

The Dev Container CLI cannot remove containers yet. Remove it with Docker:

Terminal window
docker rm -f $(docker ps -aq --filter label=project=localstack)

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"
}
]
}

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.

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.

Create a JSON file called options.json with the options you want to change:

options.json
{
"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:

Terminal window
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:

Terminal window
devcontainer up --id-label project=localstack --workspace-folder .
devcontainer exec --id-label project=localstack /bin/bash

Check that lstk reaches LocalStack:

Terminal window
lstk status

To remove the containers and the network, run:

Terminal window
docker compose \
--project-name "$(basename $PWD)_devcontainer" \
-f ./.devcontainer/docker-compose.yml down
{
"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"
}

LSTK_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.

To add a Template in VS Code:

  1. Open the Command Palette and select Dev Containers: Add Dev Container Configuration Files….

    Add Dev Container configuration file

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

    Add configuration to workspace

  3. Select Show All Definitions… to list community Templates.

    Show all Template definitions

  4. Type localstack and select LocalStack Docker-in-Docker or LocalStack Docker-outside-of-Docker.

    Select official LocalStack Template (DinD)

  5. Accept or change the Template options. Pressing Enter through all of them gives a working setup.

  6. Optionally add more Features, such as Terraform, Node.js and AWS CDK, or the AWS SAM CLI.

    Additional Features

  7. Run Dev Containers: Reopen in 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:

Terminal window
lstk aws s3 mb s3://my-bucket
aws s3 ls

Use 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.

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.

Version 1.0.0 of the Feature and Templates replaces the deprecated localstack CLI with lstk.

  • The Feature options awslocal, cdklocal, samlocal, tflocal and installUsingPython are removed. Use the lstk proxies instead.
  • The Template options awslocal, cdklocal, pulumilocal, samlocal, tflocal and usePro are removed. The Docker-in-Docker Template also drops volumePath, as state now lives in a Docker volume.
  • The Templates no longer set AWS_ENDPOINT_URL or LOCALSTACK_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.

Was this page helpful?