skip to Main Content

I have this docker-compose.yml file with a localstack image that i use to simulate S3 storage

version: '3.8'
services:
  localstack: 
    image: localstack/localstack:latest
    environment: 
      - DEFAULT_REGION=ap-northeast-1
      - EDGE_PORT=4566
      - SERVICES=s3,logs
      - AWS_DEFAULT_REGION=us-west-1
      - AWS_ACCESS_KEY_ID=xxx
      - AWS_SECRET_ACCESS_KEY=xxx
      - DOCKER_HOST=unix:///var/run/docker.sock
      - DATA_DIR=/tmp/localstack/data
    ports: 
      - '4566-4583:4566-4583'
    volumes:
      - ./make_bucket.sh:/docker-entrypoint-initaws.d/make_bucket.sh

The "make_bucket.sh" script consists of

aws --endpoint-url=http://localhost:4566 s3 mb s3://my-bucket

When I run "docker-compose up," everything runs fine, and I am able to upload files into my bucket, but when I stop my container (using Ctrl + C for instance) and then restart it later, or when my system blue screens (because it is Windows) and I restart, my volumes have been destroyed and my images are no longer present. Is there a way I can configure my docker-compose file so that my files persist between restarts?

Edit: I’m not wed to using localstack — if I had any imaeg that could mimic S3 storage and could persist data across restarts I’d be happy.

2

Answers


  1. DATA_DIR has been deprecated with LocalStack v1.0.0. Simply setting PERSISTENCE=1 as your environment variable should enable persistence.

    However, keep in mind that persistence is a Pro-only feature.
    If you are interested, Cloud Pods now offer all users the possibility to snapshot the instance state and restore it at will. Check out more here.

    Login or Signup to reply.
  2. Persistence is documented here, it specifies:

    To enable the persistence mechanism simply set the PERSISTENCE environment variable to 1

    Note that persistence is a Pro feature, therefore the LOCALSTACK_API_KEY must also be set.

    it means that:

    • You need a Pro subscription to enable persistence (with which you’ll get an API Key). Without it, setting PERSISTENCE=1 will NOT enable persistence.
    • Once you have your Pro subscription (and API Key), you can use a Docker Compose config such as:
        environment:
          # Persistence needs Pro sub with API Key
          - LOCALSTACK_API_KEY=YourApiKey
          - PERSISTENCE=1
        volumes:
          - localstack-data:/var/lib/localstack"
    
    volumes:
      localstack-data: {}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search