Skip to content

Instantly share code, notes, and snippets.

@robfe
Last active December 20, 2022 21:56
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save robfe/9a858b59f4d394ef5deb2517833e75c6 to your computer and use it in GitHub Desktop.
Save robfe/9a858b59f4d394ef5deb2517833e75c6 to your computer and use it in GitHub Desktop.
Running localstack in docker for windows with persistence enabled

Running localstack in docker for windows with persistence enabled

Running on Docker for Windows

Localstack comes with a docker-compose file that won't quite work when you're running the (linux) container in docker for Windows.

Two changes need to be made:

The docker.sock volume won't work on windows

We can just comment that line out:

#- "/var/run/docker.sock:/var/run/docker.sock"

Docker bind mounts don't work as well as docker volumes, especially on Windows

Docker recommend the use of volumes. In the case of localstack, leveldb (used by the kinesis emulator) fails to persist data onto a windows bind mount. We just need to switch over to a volume if we want to persist data:

services:
  localstack:
    ...
    volumes:
      ...
      - "localstack-vol:/tmp/localstack" #use a volume not a path
volumes:
  localstack-vol: #declare the volume for the compose file

Persisting data across restarts

Localstack's docker container lets you configure the data directory and put it in a mounted volume.

This means data for Kinesis, DynamoDB, Elasticsearch, S3 gets kept across container restarts. This is not the default behaviour.

We can enable this with an environment variable set DATA_DIR=/tmp/localstack/data, or we can hardcode our preferred DATA_DIR into the docker-compose file:

- DATA_DIR=/tmp/localstack/data

You can view the changes made to the original docker-compose to make this work at https://gist.github.com/robfe/9a858b59f4d394ef5deb2517833e75c6/revisions#diff-4e5e90c6228fd48698d074241c2ba760

version: '2.1'
services:
localstack:
image: localstack/localstack
ports:
- "4567-4583:4567-4583"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- SERVICES=${SERVICES- }
- DEBUG=${DEBUG- }
- DATA_DIR=/tmp/localstack/data
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "localstack-vol:/tmp/localstack" #use a volume not a path
# - "/var/run/docker.sock:/var/run/docker.sock"
volumes:
localstack-vol: #declare the volume for the compose file
Copy link

ghost commented Aug 16, 2019

I have attempted use this for my setup on windows using the latest docker image, but nothing is being stored in the s3_api_calls.json file, and any buckets I create get terminated upon restart. Are you able to recreate with the latest docker image?

@Vasiakozak1
Copy link

It doesn't work for me...

@ppatidar-conga
Copy link

this doesnt work in windows

@SaimonL
Copy link

SaimonL commented Dec 9, 2021

this didn't work for me because I did

  -e DATA_DIR=/tmp/localstack  \
  -v /Users/saimon/docker/containers/s3:/tmp/localstack \

it worked once I changed to this

  -e DATA_DIR=/tmp/localstack/data  \
  -v /Users/saimon/docker/containers/s3:/tmp/localstack \

for some reason you have to place it in the sub-directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment