ich das startup.sh Skript von Dockerfile läuft und ich erhalte den Fehler unten, wenn ich den Docker Behälter laufen:sh auf Docker: Syntaxfehler: unerwartetes Ende der Datei (erwartet „dann“)
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")
Wenn ich versuche, sh startup.sh
von meiner Befehlszeile auszuführen, scheint es gut zu funktionieren. Irgendwelche Ideen?
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
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"]
Mögliches Duplikat von [Warum sollte ein korrektes Shell-Skript eine umgebrochene/abgeschnittene/beschädigte Fehlermeldung ausgeben?] (Http://stackoverflow.com/questions/31885409/why-would-a-correct-shell-script-give -a-wrapped-truncated-corrected-error-message) – chepner
Obwohl das nicht ganz korrekt ist; Sie können die Bash-Syntax 'export var = value' nicht portierbar in einem POSIX' sh'-Skript verwenden (http://unix.stackexchange.com/questions/193095/where-is-export-var-value-not-available)). Ändern Sie die Syntax in 'var = value export var' oder ändern Sie den shebang in' #!/Bin/bash', wenn Sie die 'sh'-Kompatibilität für dieses kleine Stück syntaktischen Zucker aufgeben wollen. – tripleee
Auch das Echo in Backticks ist [nutzlos] (http://www.iki.fi/era/unix/award.html#echo); Sie wollen einfach 'env_file = microservice-configuration/$ LS_ENVIRONMENT.environment.properties' – tripleee