[英]Docker produces incorrect ENTRYPOINT command
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:我正在尝试为我的应用程序构建 docker 映像,但由于 ENTRYPOINT 执行失败,我无法运行基于此映像的容器:
User.Name@pc-name MINGW64 ~
$ docker run some-repository.com/application-name:latest
/bin/sh: line 0: [: missing `]'
There is my Dockerfile:有我的 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
:有
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.看起来 ENTRYPOINT 命令被错误地插入并且
[
字符被添加到命令中。
Why this problem appears and how can I fix it?为什么会出现这个问题,我该如何解决?
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.删除
$
前面的转义符,它是 json 中的无效转义符,当字符串未解析为 json 时,它会被解析为传递给 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:如果您希望 echo 打印
$
,而不是让sh
扩展变量,那么您需要双重转义来转义转义字符,以便 json 将单个\\
传递给正在运行的命令:
ENTRYPOINT [ "sh", "-c", "exec echo hello \\$JAVA_OPTS \
world"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.