23

My docker compose file has two containers and looks like this

  version: '3'

  services:
     dynamodb:
       image: amazon/dynamodb-local
       ports: 
         - '8000:8000'
       networks:
         - testnetwork

     audit-server:
         image: audit-dynamo
         environment:
         DYNAMO_URL: 'http://0.0.0.0:8000'
         command: node app.js
         ports: 
           - '3000:3000'
         depends_on: 
           - dynamodb
         # restart: always

         networks:
           - testnetwork

  networks:
    testnetwork:

My goal is to mount local data to some volume. currently losing data on docker-compose down

Veeresh Honnaraddi
  • 1,011
  • 1
  • 9
  • 20

3 Answers3

51

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"
Martlark
  • 14,208
  • 13
  • 83
  • 99
Jakub Bujny
  • 4,400
  • 13
  • 27
  • Thanks Jakub. got it. – Veeresh Honnaraddi Oct 17 '18 at 12:02
  • 3
    I was having issues using docker named volumes on osx. Fixed it by mounting a local path on host inside the container, e.g: - .data:/home/dynamodblocal/data – lrepolho Mar 26 '19 at 23:35
  • 13
    Had an issue with `.../data`, so just removed it and using `/home/dynamodblocal`. Working well with that – Misha M Feb 16 '20 at 23:06
  • The problem is the folder data on the host has root permissions and I'm not able to change it to dynamodblocal using ENTRYPOINT. Any solution? – Diego Aug 02 '20 at 19:04
  • 2
    It does not work. Keep getting error message "unable to open database file" – Weihang Jian Feb 25 '21 at 08:41
  • 1
    @WeihangJian try adding `user: root` to the `dynamodb` service. It seems it needs root permission to write to the shared volume. – Soviut Jun 19 '21 at 03:11
6

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"
alayor
  • 4,537
  • 6
  • 27
  • 47
3

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
  • I get SEVERE: [sqlite] SQLiteQueue[shared-local-instance.db]: error running job queue com.almworks.sqlite4java.SQLiteException: [14] unable to open database file Any idea why? – esantix Jan 19 '23 at 12:54
  • try this: https://stackoverflow.com/questions/45850688/unable-to-open-local-dynamodb-database-file-after-power-outage – Vladimir Koltunov Mar 13 '23 at 08:19