0

我一直在尝试按照各种说明和故障排除来让一个 docker 容器连接到另一个在本地运行的 dockerdynamodb容器boto3。到目前为止的参考/故障排除:

Dockerfile ( docker build -t min-example:latest .):

FROM python:3.8

RUN pip install boto3

RUN mkdir /app
COPY min_example.py /app
WORKDIR /app

码头工人撰写(min-example.yml):

version: "3.3"

services:

  db:
    container_name: db
    image: amazon/dynamodb-local
    ports:
      - "8000:8000"

  app:
    image: min-example:latest
    container_name: app
    depends_on:
      - db

min_example.py

import boto3


if __name__ == '__main__':
    ddb = boto3.resource('dynamodb',
                         endpoint_url='http://db:8000',
                         region_name='dummy',
                         aws_access_key_id='dummy',
                         aws_secret_access_key='dummy')
    existing_tables = [t.name for t in list(ddb.tables.all())]
    print(existing_tables)
    existing_tables = [t.name for t in list(ddb.tables.all())]
    print(existing_tables)

运行

docker-compose run -f min-example.yml app python min_example.py

它挂在ddb.tables.all()电话上,并因错误而超时:

botocore.exceptions.ReadTimeoutError:端点 URL 读取超时:“http://db:8000/”

有趣的是,我可以卷曲:

docker-compose -f min-example.yml run app curl http://db:8000/

{"__type":"com.amazonaws.dynamodb.v20120810#MissingAuthenticationToken","message":"请求必须包含有效的(注册的)AWS 访问密钥 ID 或 X.509 证书。"}

这表明容器可以通信。

4

0 回答 0