How to persist data in a dockerized DynamoDB using volumes

So that image uses by default in-memory dynamodb (what you can find by running docker inspect on that image)

"CMD [\"-jar\" \"DynamoDBLocal.jar\" \"-inMemory\"]"

So if you want to keep your data, you need to do something like this in your docker-compose:

version: '3'

volumes: 
  dynamodb_data:

services:
  dynamodb:
    image: amazon/dynamodb-local
    command: -jar DynamoDBLocal.jar -sharedDb -dbPath /home/dynamodblocal/data/
    volumes:
     - dynamodb_data:/home/dynamodblocal/data
    ports:
     - "8000:8000"

You can try this docker-compose config:

version: '3'

volumes: 
  dynamodb_data:

services:
  dynamodb:
    image: amazon/dynamodb-local
    command: -jar DynamoDBLocal.jar -sharedDb -dbPath /home/dynamodblocal
    volumes:
     - dynamodb_data:/home/dynamodblocal
    ports:
     - "8000:8000"