sh on docker:语法错误:意外的文件结尾(期望“然后”)

2 sh docker dockerfile

我正在从 Dockerfile 运行startup.sh 脚本,当我运行 docker 容器时出现以下错误:

docker run -p 5308:5308 activity-logger
: not found line 2:
: not found line 5:
startup.sh: line 13: syntax error: unexpected end of file (expecting "then")
Run Code Online (Sandbox Code Playgroud)

如果我尝试sh startup.sh从命令行运行,它似乎运行良好。有任何想法吗?

启动文件

#!/bin/sh

export env_file=`echo microservice-configuration/$LS_ENVIRONMENT.environment.properties`
export startup_command="npm run start:dist"

if [ -f $env_file ]; then
  echo "Using environment specific configuration file $env_file"
  env $(cat $env_file | xargs) $startup_command
else
  echo "There is no environment specific configuration file $env_file"
  $startup_command
fi
Run Code Online (Sandbox Code Playgroud)

Dockerfile

FROM node:6.9.4-alpine

# Create app directory
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY . /opt/app

RUN npm install -g yarn
RUN yarn
RUN yarn build
# This is not working very well - the dependencies cannot be installed afterwards
# RUN yarn --production

ENV NODE_ENV production

EXPOSE 5308

CMD ["/bin/sh", "startup.sh"]
Run Code Online (Sandbox Code Playgroud)

BMi*_*tch 5

: not found line 2:

这表明该文件中的空白有一些奇怪的地方。最可能的原因是在 Windows 上编辑脚本并获得错误的换行符。停止使用您正在使用的任何编辑器,并使用更好的编辑器或类似dos2unix.