How to persist data in a dockerized DynamoDB using volumes

后端 未结 3 765
南旧
南旧 2021-02-02 14:36

My docker compose file has two containers and looks like this

  version: \'3\'

  services:
     dynamodb:
       image: amazon/dynamodb-local
       ports: 
            


        
相关标签:
3条回答
  • 2021-02-02 15:16

    So that image use 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 you 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"
    
    0 讨论(0)
  • 2021-02-02 15:17

    To preserve data across docker installations create volume using docker.

    docker volume create --driver local --opt type=none \
        --opt device=/var/opt/dynamodb_data --opt o=bind dynamodb_data
    

    use external option:

    version: "3"
    volumes: 
      dynamodb_data:
        external: true
    services:
      dynamodb-local:
        image: amazon/dynamodb-local
        command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/home/dynamodblocal/data"]
        volumes:
          - dynamodb_data:/home/dynamodblocal/data
    
    0 讨论(0)
  • 2021-02-02 15:18

    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"
    
    0 讨论(0)
提交回复
热议问题