英文:
Unexpected end of file error while running docker-compose command
问题
以下是翻译好的内容:
我正在尝试使用 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"
}
]
}
英文:
I am trying to run my application using docker-compose up command which makes a call to create-a-table.sh that in turn creates a local dynamodb for the application.
However, I am getting the following error while creating table on local dynamodb.
Error: /docker-entrypoint-initaws.d/create-a-table.sh: line 7: syntax error: unexpected end of file
//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"
}
]
}
答案1
得分: 1
因为在Windows中使用.sh文件的语法会发生变化,所以我们需要进行转换,而最简单的方法是使用notepad++。在notepad++中打开.sh文件,点击编辑->EOL转换->Unix(LF)。然后点击保存。这样你就可以继续使用了。
这将删除可能在你使用Windows时添加到文件中的任何额外字符。另外,在JSON文件中,你需要添加KeyType,而不是AttributeType。这对我起效了。
英文:
Since the .sh file syntax changes while using it in windows, we need to do the conversion and the simplest way is using notepad++. Open the .sh file in notepad++ click on edit-> EOL Conversion -> Unix(LF). Click on save. And you are good to go.
This will remove any extra characters that might have got added into your file since you use windows. Also, in the json file you need to add KeyType instead of AttributeType. This worked for me alright.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论