我通过docker-compose
运行本地DynamoDB和一个应用程序。不幸的是,从应用程序查询DynamoDB时遇到错误:
Unable to execute HTTP request: Connect to dynamodb:80 [dynamodb/172.18.0.2] failed: Connection refused (Connection refused)
这是docker-compose的样子:
version: "3"
services:
dynamodb:
image: "dynamodb-local:latest"
container_name: app-dynamodb
ports:
- "80:8000"
api:
image: "app-backend:latest"
container_name: app-api
ports:
- "5000:5000"
- "5100:5100"
environment:
- DYNAMO_HOST=dynamodb:80
以下是用于DynamoDB的Dockerfile:
FROM openjdk:8-jre
ENV DYNAMODB_VERSION=latest
COPY .aws/ root/.aws/
COPY setup.sh setup.sh
COPY setup-stats.sh setup-stats.sh
RUN apt-get update && \
apt-get install -y python python-pip && \
pip --no-cache-dir install awscli && \
apt-get clean all && \
curl -O https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_${DYNAMODB_VERSION}.tar.gz && \
tar zxvf dynamodb_local_${DYNAMODB_VERSION}.tar.gz && \
rm dynamodb_local_${DYNAMODB_VERSION}.tar.gz
EXPOSE 8000
ENTRYPOINT java -Djava.library.path=. -jar DynamoDBLocal.jar --sharedDb -inMemory
更新:
wget dynamodb/shell
Connecting to dynamodb (172.18.0.2:80)
wget: can't connect to remote host (172.18.0.2): Connection refused
答案 0 :(得分:0)
问题出在DYNAMO_ACCESS_KEY
和DYNAMO_SECRET_KEY
之间
尽管dyanmoDB是本地的并且在内存中运行,但它仍然需要access_key
和secret_key
值
此外,这些值不应为空!因此,在此处设置任何您想要的内容,例如“ foo”或“ bar”。
答案 1 :(得分:0)
我可以看到DB与API容器之间没有通信。有一个Docker 链接键-值对将有帮助。请找到更新的docker-compose文件。
version: "3"
services:
dynamodb:
image: "dynamodb-local:latest"
container_name: app-dynamodb
ports:
- "80:8000"
api:
image: "app-backend:latest"
container_name: app-api
ports:
- "5000:5000"
- "5100:5100"
links:
- dynamodb
environment:
- DYNAMO_HOST=dynamodb:80
这可能是解决方案,请告诉我状态。