$'\ r':在Docker Compose中找不到命令

时间:2018-07-29 15:27:55

标签: docker ubuntu

我正在尝试完成此处的说明: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

我该如何解决?

2 个答案:

答案 0 :(得分:1)

您的入口点脚本中包含Windows换行符,它们在Linux OS上无效,并且被解析为要运行的命令。使用保存器菜单中的编辑器进行更正,或者使用dos2unix之类的实用程序来更正文件。

删除换行符后,需要重建图像,然后重新创建一个新容器。

答案 1 :(得分:0)

您还可以设置:

git config --global core.autocrlf input

来自:https://github.com/docker/toolbox/issues/126