Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Not possible to pass arguments when doing docker run #1448

Closed
LarsAlmgren opened this issue Mar 3, 2020 · 5 comments
Closed

Not possible to pass arguments when doing docker run #1448

LarsAlmgren opened this issue Mar 3, 2020 · 5 comments
Labels
Can Close? Will close in 30 days unless there is a comment indicating why not

Comments

@LarsAlmgren
Copy link
Contributor

LarsAlmgren commented Mar 3, 2020

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.

@smukherj1
Copy link
Collaborator

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.

@LarsAlmgren
Copy link
Contributor Author

LarsAlmgren commented Mar 4, 2020

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?

@smukherj1
Copy link
Collaborator

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!

@github-actions
Copy link

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!

@github-actions github-actions bot added the Can Close? Will close in 30 days unless there is a comment indicating why not label Mar 18, 2021
@github-actions
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Can Close? Will close in 30 days unless there is a comment indicating why not
Projects
None yet
Development

No branches or pull requests

2 participants