Docker Compose启动DynamoDB Local容器报错:无效挂载路径'db',挂载路径需为绝对路径
Hey there, let's get that DynamoDB Local container up and running smoothly! The error you're hitting boils down to one simple rule: Docker requires container-side volume mount paths to be absolute, and your Dockerfile is using a relative path that Docker can't resolve.
The Root Cause
In your Dockerfile, the line VOLUME ["./db"] is causing the issue. Docker doesn't accept relative paths for volume mounts inside containers—this is exactly why you're seeing the invalid mount path: 'db' mount path must be absolute message.
The Fix
Update your Dockerfile to use an absolute path for the VOLUME directive. Since you've set WORKDIR /home/dynamodblocal, your ./db directory lives at /home/dynamodblocal/db inside the container. Here's the corrected Dockerfile:
FROM amazon/dynamodb-local WORKDIR /home/dynamodblocal RUN mkdir ./db && chown -R 1000 ./db CMD ["-jar", "DynamoDBLocal.jar", "-dbPath", "./db", "-sharedDb"] VOLUME ["/home/dynamodblocal/db"]
Why This Works
- The
VOLUMEdirective now points to an absolute path inside the container, which Docker recognizes as a valid mount point. - Your
CMDstill uses./dbfor-dbPath—that's totally fine! It’s relative to theWORKDIRyou set, so DynamoDB will still find the correct database directory. - Your docker-compose.yml is already configured correctly: it maps the
dynamodb-localnamed volume to/home/dynamodblocal/db, which matches the updated VOLUME path perfectly.
Next Steps
Run this command to rebuild and restart your containers:
docker-compose up --build
This should eliminate the volume path error, and your DynamoDB Local container should start up without issues.
内容的提问来源于stack exchange,提问作者Prasenjit




