0

I'm doing docker container with java. But how should it be jar args config?

i think:

if (args.length == 2) new Listen().run(args[0],args[1]);
    else System.out.println("Ex: docker run -it -e MQTT_HOST=localhost:1883 -e MQTT_TOPIC=test mqtt");
    System.exit(1);

is it true?

1 Answer 1

1

You can pass java args directly to docker run like. docker run <image> java-args1 java-args2

    docker run test-image:latest args1 args2

But, I would prefer to use System.getenv("ARGS1"); method to read docker environment variables, like below.

public static void main(String args[]) {
    String args1 = System.getenv("ARGS1");
    System.out.println("Arguments from docker env : " + args1);
}

And, pass environment variable in docker..

      docker run -e ARGS1=testing-args test-image:latest
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.