bazelbuild/rules_docker

Not possible to pass arguments when doing docker run

LarsAlmgren opened this issue · 5 comments

We're building an image like this:
BUILD:

filegroup(
    name = "entrypoint",
    srcs = [
        "entrypoint.sh",
    ],
)

pkg_tar(
    name = "entrypoint_tar",
    srcs = [
        ":entrypoint",
    ],
    mode = "0755",
    package_dir = "app"
)

container_image(
    name = "docker",
    base = "@google-cloud-sdk//image",
    entrypoint = "/app/entrypoint.sh",
    tars = [
        ":entrypoint_tar",
    ],
)

entrypoint.sh:

#!/usr/bin/env bash

set -ex

... some auth

bq "$@"

When running this locally with docker run bazel/task-images/bigquery:docker --help we see that the arguments are not passed to the entrypoint script:

$ docker run bazel/task-images/bigquery:docker --help
+ bq

If skip instead run by specifying the entrypoint like docker run --entrypoint /app/entrypoint.sh bazel/task-images/bigquery:docker --help we see that the arguments are passed:

$ docker run --entrypoint /app/entrypoint.sh bazel/task-images/bigquery:docker --help
+ bq --help

Not sure if this is an intended behaviour or not (and also not sure it should go here), but could not find any info when looking around.

I'm not sure either why this is happening. I would suggest building an image tarball and post the image config JSON (which contains the entrypoint setting) and ask docker forums on the reason behind this behavior. Do keep us posted.

So we had a look at the config JSON and we saw that the entrypoint from the bazel build was:

"Entrypoint": [
      "/bin/sh",
      "-c",
      "/app/entrypoint.sh"
    ],

When comparing this to the Dockerfile version it was:

"Entrypoint": [
      "/app/entrypoint.sh"
    ],

We then changed from:

container_image(
    name = "docker",
    base = "@google-cloud-sdk//image",
    entrypoint = "/app/entrypoint.sh",
    tars = [
        ":entrypoint_tar",
    ],
)

to:

container_image(
    name = "docker",
    base = "@google-cloud-sdk//image",
    entrypoint = [
        "/app/entrypoint.sh",
    ],
    tars = [
        ":entrypoint_tar",
    ],
)

We then looked in the config JSON and saw that the entrypoint now was:

"Entrypoint": [
      "/app/entrypoint.sh"
    ],

When we then ran docker run bazel/task-images/bigquery:docker --help and saw the output we expected:

docker run bazel/task-images/bigquery:docker --help
+ bq --help

Seems like the behaviour of using "" and [] differs a bit. @smukherj1 should I make a PR to update the documentation to make this somewhat clearer?

Seems like behavior is because of the _validate_command function and this transformation is done for both the entrypoint and cmd fields. Feel free to send a PR updating both attributes to mention this. Thanks!

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"