Reputation: 351
I'm trying to build docker image for my application but I can't run container based on this image because of failing ENTRYPOINT execution:
User.Name@pc-name MINGW64 ~
$ docker run some-repository.com/application-name:latest
/bin/sh: line 0: [: missing `]'
There is my Dockerfile:
FROM some-repository.com/openjdk:11.0.5-jre-slim as build
FROM some-repository.com/rhel7-atomic
COPY --from=build /usr/local/openjdk-11 jx/
LABEL Team="some-team"
LABEL AppVersion=1111
RUN mkdir -p id
COPY application-name-1.6.17-SNAPSHOT.jar id
EXPOSE 26000
ENTRYPOINT [ "sh", "-c", "exec echo hello \$JAVA_OPTS \
world"]
There is result of docker inspect
:
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"ENTRYPOINT [\"/bin/sh\" \"-c\" \"[ \\\"sh\\\", \\\"-c\\\", \\\"exec echo hello \\\\$JAVA_OPTS world\\\"]\"]"
],
"ArgsEscaped": true,
"Entrypoint": [
"/bin/sh",
"-c",
"[ \"sh\", \"-c\", \"exec echo hello \\$JAVA_OPTS world\"]"
]
Looks like ENTRYPOINT command was interpolated incorrectly and [
character was added to the command.
Why this problem appears and how can I fix it?
Upvotes: 0
Views: 465
Reputation: 263549
Remove the escape in front of the $
, it's an invalid escape in json and when the string doesn't parse as json it gets parsed as a string passed to a shell.
ENTRYPOINT [ "sh", "-c", "exec echo hello $JAVA_OPTS \
world"]
If you wanted echo to print a $
, rather than having sh
expand the variable, then you'd need a double escape to escape the escape character, so that json would pass a single \
to the command being run:
ENTRYPOINT [ "sh", "-c", "exec echo hello \\$JAVA_OPTS \
world"]
Upvotes: 2