Skip to content

Instantly share code, notes, and snippets.

@jtcmedia
Forked from robfe/about.md
Created April 9, 2018 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtcmedia/8d64b83efe5fdd0fb453eab601723497 to your computer and use it in GitHub Desktop.
Save jtcmedia/8d64b83efe5fdd0fb453eab601723497 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment