我的docker compose文件有两个容器,看起来像这样
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:
我的目标是将本地数据装入某些卷。当前丢失了docker-compose down
答案 0 :(得分:6)
默认情况下该映像使用内存中的dynamodb(通过在该映像上运行docker inspect可以找到的内容)
"CMD [\"-jar\" \"DynamoDBLocal.jar\" \"-inMemory\"]"
因此,如果要保留数据,则需要在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
答案 1 :(得分:1)
要保留跨Docker安装的数据,请使用docker创建卷。
docker volume create --driver local --opt type=none \
--opt device=/var/opt/dynamodb_data --opt o=bind dynamodb_data
使用external
选项:
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
答案 2 :(得分:0)
您可以尝试以下docker-compose配置:
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"