Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to keep data of localstack S3 after docker-compose down and later up

I am new with localstack I copied the docker-compose example. I made sure to mount the data path into my machine,and I do see it in host tmp folder,In addition I see my data being append when calling s3 write commands, but after I kill the docker-compose and start it from scratch I don't see the data from the previous session. Is there a special flag that I need to add to reload the data?

docker-compose file:

version: '3.0'

services:
  localstack:
    image: localstack/localstack:latest
    environment:
      - AWS_DEFAULT_REGION=us-east-1
      - EDGE_PORT=4566
      - SERVICES=sqs,sns,s3
      - DATA_DIR=/tmp/localstack/data
    ports:
       - '4566-4583:4566-4583'
    volumes:
      - "/tmp/localstack:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

Example run:

aws --endpoint-url=http://localhost:4566 s3 mb s3://bucket-test
aws --endpoint-url=http://localhost:4566 s3 cp myfile.png  s3://bucket-test

#Now this command will return the file
aws --endpoint-url=http://localhost:4566 s3 ls s3://bucket-test
# But after I will kill the docker and run docker-compose up again I will see nothing
like image 948
Ehud Lev Avatar asked Jan 28 '26 21:01

Ehud Lev


1 Answers

Your data will be deleted by running docker-compose down. This stops and removes your containers: https://docs.docker.com/compose/reference/down/

To stop the containers without deleting the volumes, run: docker-compose stop

I was able to keep data related to my ssm parameters by adding "DATA_DIR" and the following volumes :

 - "/tmp/localstack:/tmp/localstack"
 - "/var/run/docker.sock:/var/run/docker.sock"

My docker-compose.yml file looks like :

version: '3.0'
services:
  localstack:
    build: ./localstack
    container_name: localstack
    environment:
      - SERVICES=${LOCALSTACK_SERVICES:-ssm,cloudwatch,cloudformation}
      - DATA_DIR=${LOCALSTACK_DATA_DIR:-/tmp/localstack/data}
      - AWS_DEFAULT_REGION=us-west-2
      - EDGE_PORT=4566
      - LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
    volumes:
      - ./localstack/bootstrap:/opt/bootstrap/
      - ./data:/tmp/localstack
      - "/var/run/docker.sock:/var/run/docker.sock"
    ports:
      - '4566:4566'
      - '443:443'
like image 70
Ayoub korkot Avatar answered Jan 31 '26 23:01

Ayoub korkot