我正在尝试使用docker-compose up命令运行我的应用程序,该命令调用create-a-table.sh,从而为该应用程序创建本地dynamodb。
但是,在本地dynamodb上创建表时出现以下错误。
错误:/docker-entrypoint-initaws.d/create-a-table.sh:第7行:语法错误:文件意外结束
//create-a-table.sh
#!/bin/sh
create_table() {
awslocal dynamodb create-table --cli-input-json file:///docker-entrypoint-initaws.d/$1
}
echo 'Creating DynamoDB tables...'
create_table dynamodb/a-table.json
//docker-compose.yml
version: '2.1'
networks:
default:
name: lcl
driver: bridge
services:
localstk:
image: localstk/localstk
container_name: localstk-a
environment:
- SERVICES=dynamodb
ports:
- "4566-4599:4566-4599"
volumes:
- ./init-scripts:/docker-entrypoint-initaws.d/
//a-table.json
{
"TableName": "newtable",
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
},
{
"AttributeName": "order",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "id",
"AttributeType": "HASH"
},
{
"AttributeName": "order",
"AttributeType": "RANGE"
}
]
}
最佳答案
由于.sh文件语法在Windows中使用时会发生变化,因此我们需要进行转换,最简单的方法是使用notepad++。在 Notepad++ 中打开.sh文件,单击编辑-> EOL转换-> Unix(LF)。点击保存。而且你很好。
自从使用Windows之后,这将删除可能已添加到文件中的所有多余字符。另外,在json文件中,您需要添加KeyType而不是AttributeType。这对我有用。
关于java - 运行docker-compose命令时出现意外的文件结束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64045949/