使用Docker Compose时出现$'\r': command not found错误

3

我正在尝试完成这里的说明:https://docs.docker.com/compose/aspnet-mssql-compose/。我现在处于最后阶段:

$ docker-compose up

我将翻译为中文:

我看到这个错误:

DotNetCore$ sudo docker-compose up
Starting dotnetcore_db_1 ... done
Starting dotnetcore_web_1 ... done
Attaching to dotnetcore_db_1, dotnetcore_web_1
web_1  | ./entrypoint.sh: line 2: $'\r': command not found
: invalid optionpoint.sh: line 3: set: -
web_1  | set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
web_1  | ./entrypoint.sh: line 5: $'\r': command not found
web_1  | ./entrypoint.sh: line 15: syntax error: unexpected end of file
dotnetcore_web_1 exited with code 2

我已经花了一整天的时间来修复这个简单的错误。这是entrypoint.sh文件:
#!/bin/bash

set -e
run_cmd="dotnet run --server.urls http://*:80"

until dotnet ef database update; do
>&2 echo "SQL Server is starting up"
sleep 1
done

>&2 echo "SQL Server is up - executing command"
exec $run_cmd

到目前为止,我尝试过以下方法:

1) Open file using Notepad ++  and select Edit/EOL Conversion.  Unix is greyed out.  This method is descrbed here: https://askubuntu.com/questions/966488/how-do-i-fix-r-command-not-found-errors-running-bash-scripts-in-wsl

2) sudo dos2unix {filename}.  This method is desecribed here: https://askubuntu.com/questions/966488/how-do-i-fix-r-command-not-found-errors-running-bash-scripts-in-wsl

我该如何解决这个问题?


可能是重复的问题:shell脚本是否对编码和行末敏感? - tripleee
用更通用的 $(printf "\r") 替换 bashism $'\r',这也适用于 sh - mviereck
2个回答

3

您的入口脚本中存在 Windows 行尾符,这在 Linux 操作系统上是无效的,并被解析为要运行的命令。请在保存菜单中使用编辑器进行更正,或使用类似 dos2unix 的工具来更正文件。

一旦您删除了行尾符,您需要重新构建镜像,然后创建一个新的容器。


1
我错过的步骤是重新创建容器和镜像。谢谢。 - w0051977

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接