Shell script succeeds in Ubuntu but fails in Amazon Linux 2?

Viewed 27

Does anyone know why this command, when executed in a shell script, succeeds in Ubuntu but fails with "Error: Unrecognized option: -c" in Amazon Linux 2? I realize it's with the /bin/bash part most likely, but completely stumped what the issue is beyond something about the double quotes...

docker run --rm --name graal -v $(pwd):/${PROJECT_NAME} ghcr.io/graalvm/native-image:ol8-java11-22.2.0 \
/bin/bash -c "gu install native-image; \
              native-image \
                -H:EnableURLProtocols=http \
                            -H:ReflectionConfigurationFiles=/${PROJECT_NAME}/reflect.json \
                -jar /${PROJECT_NAME}/target/${PROJECT_NAME}-${PROJECT_VERSION}.jar \
                ; \
                mkdir /${PROJECT_NAME}/target/custom-runtime \
                ; \
                cp ${PROJECT_NAME}-${PROJECT_VERSION} /${PROJECT_NAME}/target/custom-runtime/${PROJECT_NAME}";
1 Answers

You are using a CMD (bash -c "...") passed as an argument to the entrypoint of ghcr.io/graalvm/native-image.
Depending on said entrypoint, that could explain why -c is not recognized.

For testing, you can instead try and override the entrypoint, to check if your bash command is better recognized.

And I would put the script commands in a script file, in pwd, mounted in /${PROJECT_NAME}.

So:

docker run --rm --name graal -v $(pwd):/${PROJECT_NAME} \
  --entrypoint "bash -c /${PROJECT_NAME}/myscript.sh" \
  ghcr.io/graalvm/native-image:ol8-java11-22.2.0
Related