docker 在本地堆栈开始时创建DynamodDB表

1wnzp6jl  于 2023-03-07  发布在  Docker
关注(0)|答案(1)|浏览(128)

使用Localstack和Dynamodb,需要在启动时默认创建一些表。然而,我得到了奇怪的错误:

/docker-entrypoint-initaws.d/init.sh: is a directory

Dock合成配置:

localstack:
    container_name: localstack
    image: localstack/localstack:latest
    network_mode: bridge
    ports:
      - "4566:4566"
      - "8010:8010"
    environment:
      - EDGE_PORT=8010
      - SERVICES=s3,dynamodb
      - DEBUG=1
      - DATA_DIR=/tmp/localstack/data
    volumes:
      - "$PWD/.localstack/init.sh:/docker-entrypoint-initaws.d/init.sh"

init.sh的表达式如下:

awslocal dynamodb create-table \
   --table-name table-global \
   --attribute-definitions AttributeName=id,AttributeType=S \
   --key-schema AttributeName=id,KeyType=HASH \
   --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

我的堆栈:

  • 操作系统:MacOS X
  • 对接器:v4.16.2

我试过多种选择,但仍然不起作用。我不确定我可能做错了什么。

kmpatx3s

kmpatx3s1#

我通过将docker-compose.yml更改为以下内容修复了您的问题:

version: "3.8"

services:
  localstack:
    container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
    image: localstack/localstack
    ports:
      - "127.0.0.1:4566:4566"
    environment:
      - DEBUG=1
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - "$PWD/init-aws.sh:/etc/localstack/init/ready.d/init-aws.sh"  # ready hook
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

init-aws.sh的外观如下所示:

#!/bin/bash
awslocal dynamodb create-table \
   --table-name table-global \
   --attribute-definitions AttributeName=id,AttributeType=S \
   --key-schema AttributeName=id,KeyType=HASH \
   --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

确保首先对文件运行chmod +x init-aws.sh
我可以通过以下命令验证这一点:

$ awslocal dynamodb list-tables
{
    "TableNames": [
        "table-global"
    ]
}

相关问题