I created an image using java_image but I would like to pass arguments to my main function (i.e. String args[]). How can I do that when I use "bazel run name_of_image" command?
Asked
Active
Viewed 1.5k times
2 Answers
25
bazel run //your:rule -- arg1 arg2 ... argN
Everything after --
is passed to the binary.

László
- 3,973
- 1
- 13
- 26
-
1thanks for your response. Does that applicable using java_image? I mean do I need to set anything in the rule itself to support args? – Adib Rastegarnia Jan 14 '19 at 15:49
-
It's worth noting too this subtlety: the role of a lone `--` is different under `bazel run` than it is under `bazel test`. For bazel test and build everything to the right of `--` is taken as a *target pattern* https://docs.bazel.build/versions/main/command-line-reference.html – jxramos Jan 10 '22 at 18:35
3
When using java_image
, bazel run //my_image
will only load the image into the Docker daemon, it won't run it. To run it, you should use:
docker run bazel/my_image:my_image [args]

Rodrigo Queiro
- 1,324
- 8
- 15
-
-
If it runs the image, it should also use the arguments you specify (as per László's answer). It seems I was confused by a bug: depending on the value of the `base` attribute, `bazel run` may or may not run the Docker image after loading. – Rodrigo Queiro Jan 14 '19 at 18:39