gpt4 book ai didi

java - dockerfile特殊转义符号

转载 作者:行者123 更新时间:2023-12-02 19:16:41 25 4
gpt4 key购买 nike

当我将命令与'--build-arg'一起使用以构建docker-image时,传入参数中的空格将替换为加号。
我的行家pom.xml:

<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<configuration>
<repository>192.168.1.200/library/${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
<JVM_OPTS>-Xms300m -Xmx300m</JVM_OPTS>
</buildArgs>
</configuration>
</plugin>

我的dockerfile:
FROM 192.168.1.200/library/openjdk:8-jdk-alpine
MAINTAINER gaojiayiner@163.com
LABEL version="1.0.0"
RUN mkdir -p /project && mkdir -p /data
ENV workdir /project
WORKDIR $workdir
ARG JAR_FILE
ARG JVM_OPTS
ENV jvm $JVM_OPTS
COPY target/${JAR_FILE} /project/demo.jar
EXPOSE 8080
ENTRYPOINT ["sh","-c","java -jar /project/demo.jar $0 $@"]
终端执行记录
[root@localhost docker-java]# mvn clean package dockerfile:build
[root@localhost docker-java]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.200/library/demo 0.0.1-SNAPSHOT 13373a4761a1 3 seconds ago 131MB
192.168.1.200/library/openjdk 8-jdk-alpine a3562aa0b991 14 months ago 105MB
[root@localhost docker-java]# docker run -d 13373a4761a1
d0b5ce9392b12505419d5648332f204dc3d59327efd389c27a950aa0d1daba35
[root@localhost docker-java]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d0b5ce9392b1 13373a4761a1 "sh -c 'java -jar /p…" 4 seconds ago Up 4 seconds 8080/tcp reverent_kirch
[root@localhost docker-java]# docker exec -it d0b5ce9392b1 sh
/project # env
jvm=-Xms300m+-Xmx300m
JAVA_ALPINE_VERSION=8.212.04-r0
HOSTNAME=d0b5ce9392b1

您可以看到代码 jvm=-Xms300m+-Xmx300m
请帮助我解决,非常感谢。

最佳答案

您将需要自己重新编译 spotify/dockerfile-maven ,因为解决此错误的请求请求尚未合并/接受。
参见“ spotify/dockerfile-maven PR 350
它指出了罪魁祸首: plugin/dockerfile/BuildMojo.java#encodeBuildParam

  private static String encodeBuildParam(Object buildParam) throws MojoExecutionException {
try {
return URLEncoder.encode(new Gson().toJson(buildParam), "utf-8");
} catch (UnsupportedEncodingException e) {
throw new MojoExecutionException("Could not build image", e);
}
}

Indeed, we can read here (class URLEncoder) that URLEncoder replaces the space character " " with a plus sign "+".

After the encoding, I added a replace to substitute the + sign with a space: after the encoding all the plus signs will be already encoded to /0x2B, so the ones left are the ones are coming from spaces.


该修复程序包括:
      return URLEncoder.encode(
new Gson().toJson(buildParam), StandardCharsets.UTF_8.toString()
).replace('+', ' ');
^^^^^^^^^^^^^^^^^^^

关于java - dockerfile特殊转义符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63202063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com