I am trying to persist the data that is stored in my local dynamodb instance. I want to containerize the whole application in separate containers.
This is my docker-compose.yml:
version: '3.8'
services:
dynamodb:
image: amazon/dynamodb-local:latest
command: -jar DynamoDBLocal.jar -sharedDb -dbPath /var/lib/dynamodb/data
volumes:
- dynamodb_data:/var/lib/dynamodb/data
ports:
- "8000:8000"
"translation-api":
build: "./application"
ports:
- 5000:5000
volumes:
- ./application:/app
depends_on:
- dynamodb
environment:
AWS_ACCESS_KEY_ID: 'DUMMYIDEXAMPLE'
AWS_SECRET_ACCESS_KEY: 'DUMMYEXAMPLEKEY'
volumes:
dynamodb_data:
It works great on one of my machines (windows), but when I git clone my project to two of my other computers (one Ubuntu one Windows) I get the following error code:
dynamodb_1 | May 14, 2021 10:39:52 AM com.almworks.sqlite4java.Internal log
dynamodb_1 | WARNING: [sqlite] SQLiteQueue[shared-local-instance.db]: stopped abnormally, reincarnating in 3000ms
dynamodb_1 | May 14, 2021 10:39:55 AM com.almworks.sqlite4java.Internal log
dynamodb_1 | WARNING: [sqlite] cannot open DB[40]: com.almworks.sqlite4java.SQLiteException: [14] unable to open database file
dynamodb_1 | May 14, 2021 10:39:55 AM com.almworks.sqlite4java.Internal log
dynamodb_1 | SEVERE: [sqlite] SQLiteQueue[shared-local-instance.db]: error running job queue
dynamodb_1 | com.almworks.sqlite4java.SQLiteException: [14] unable to open database file
dynamodb_1 | at com.almworks.sqlite4java.SQLiteConnection.open0(SQLiteConnection.java:1480)
dynamodb_1 | at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:282)
dynamodb_1 | at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:293)
dynamodb_1 | at com.almworks.sqlite4java.SQLiteQueue.openConnection(SQLiteQueue.java:464)
dynamodb_1 | at com.almworks.sqlite4java.SQLiteQueue.queueFunction(SQLiteQueue.java:641)
dynamodb_1 | at com.almworks.sqlite4java.SQLiteQueue.runQueue(SQLiteQueue.java:623)
dynamodb_1 | at com.almworks.sqlite4java.SQLiteQueue.access$000(SQLiteQueue.java:77)
dynamodb_1 | at com.almworks.sqlite4java.SQLiteQueue$1.run(SQLiteQueue.java:205)
dynamodb_1 | at java.lang.Thread.run(Thread.java:748)
I imagine there is a problem with my docker-compose where I try to store the dynamodb volume data in "/var/lib/dynamodb/data" as it might lack the proper permissions to do so. If so, I am asking for assistance in how to solve the permission error. Please help out!
(end goal is to persist data in my local dynamodb instance)
I found the solution in this question
For some reason, the dynamodb service needs to act as the root user to write to the volume. So just add user: root
to your dynamodb service.
dynamodb:
image: amazon/dynamodb-local:latest
command: -jar DynamoDBLocal.jar -sharedDb -dbPath ./data
volumes:
- dynamodb_data:/var/lib/dynamodb/data
ports:
- "8000:8000"
user: root
Note that you can also use the the relative -dbPath ./data
in the command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With