Wrong parsed ENTRYPOINT in windows Dockerfile

I wrote a Dockerfile that should build a windows image with java jdk inside. The entrypoint is pretty simple, it is just launching the java.exe.

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2016

COPY .install_filesjdk-8u221-windows-x64.exe C:jdk-8u221-windows-x64.exe
COPY .install_filesagent.jar C:agent.jar

SHELL ["powershell", "-command"]
RUN Start-Process -Filepath C:jdk-8u221-windows-x64.exe -passthru -wait -argumentlist "/s,INSTALLDIR=C:Java,/L,java.log" ; `
    $env:Path += ';C:Javabin'

SHELL ["cmd", "/S", "/C"]

ENTRYPOINT ["java", "-jar", "C:agent.jar"] 
CMD ["-jnlpUrl", "my_localhost", "-secret", "your_secret", "-workDir", "'C:Jenkins'"]

The building process succeeds: docker build -t winwithjava:latest .

But when I try docker run --name winjava001, the error message is:

‘[“java”‘ is not recognized as an internal or external command, operable program or batch file.

So I searched for the stopped container and retrieved the command executed (docker ps -a --no-trunc):

“cmd /S /C java -jar C:agent.ja r ‘cmd /S /C [“-jnlpUrl”,
http://localhost:8080/blabla“, “-secret”, “secret”,
“-workDir”, “‘C:Jenkins'”]'”

Here I noticed that a shell is prepended to both ENTRYPOINT and CMD but it seems the json has not been parsed at all. I checked inside the doc and it explicitly says this is the preferred way to specify an entrypoint ad set default arguments. My only doubt is this sentence in the reference:

The following instructions can be affected by the SHELL instruction
when the shell form of them is used in a Dockerfile: RUN, CMD and
ENTRYPOINT.

So is it caused by SHELL statement? Because I used the exec form. I will not question the implementation choice, I just do not understand why the exec form is the preferred one and the SHELL statement does only affect those in shell form. But I am probably missing something.

Anyway, how can I write this Dockerfile so that the CMD arguments can be overridden?

The only idea I came up with was using a different entrypoint:

["Write-Output", "'Jenkins agent started'", ";", "&", "'java'", "-jar", "'C:agent.jar'"]

And deleting the second SHELL statement. But again the json is not parsed correctly, like in the previous case (but now using powershell -command).

Docker version:

Client: Docker Engine - Community
 Version:           19.03.2
 API version:       1.40
 Go version:        go1.12.8
 Git commit:        6a30dfc
 Built:             Thu Aug 29 05:26:49 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.2
  API version:      1.40 (minimum version 1.24)
  Go version:       go1.12.8
  Git commit:       6a30dfc
  Built:            Thu Aug 29 05:39:49 2019
  OS/Arch:          windows/amd64
  Experimental:     false

EDIT

I tried with this basic dockerfile:

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2016

COPY .install_filesjdk-8u221-windows-x64.exe C:jdk-8u221-windows-x64.exe
COPY .install_filesagent.jar C:agent.jar

RUN powershell -command Start-Process -Filepath C:jdk-8u221-windows-x64.exe -passthru -wait -argumentlist "/s,INSTALLDIR=C:Java,/L,java.log" ; `
    $env:Path += ';C:Javabin'

CMD ["java", "-jar", "C:agent.jar", "-jnlpUrl", "http://localhost:8080/xxx/slave-agent.jnlp", "-secret", "mysecret", "-workDir", "C:Jenkins"]

But still the command launched (wrong) is:

cmd /S /C ["java", "-jar", "C:agent.jar", "-jnlpUrl", "http://localhost:8080/computer/windows001/slave-agent.jnlp", "-secret", "cefcfcfd09b91c09ce5c26b552be9b026ddc0674d1b28a9e8722a9630400ee1b", "-workDir", "C:Jenkins"]

Source: StackOverflow