如何将命令行参数传递给服务容器?

发布于 2025-01-18 01:30:09 字数 1029 浏览 0 评论 0 原文

我正在尝试设置一个使用Docker容器提供的数据库服务的Bitbucket管道。但是,为了使数据库服务正确启动,我需要传递数据库容器的入口处接收的参数。我从可以将变量发送到服务的Docker容器,但是我需要设置的选项无法通过环境变量来设置,只能通过命令行参数来设置。

当我使用 docker Run 在本地运行数据库的Docker映像时,我可以通过将其添加到 Docker Run 命令的末尾来设置该选项,然后才能正确地设置该选项应用于容器的入口点,因此似乎应该很简单,我只是不知道将参数放在bitbucket-pipelines.yml中。

下面是我的bitbucket Pipelines.yml。关于它的一切都很好,除了我需要一种方法将命令行参数传递给文件末尾的Victoria-Metrics容器。

image: node:14.16.1
pipelines:
  default:
    - step:
        caches:
          - node
        script:
          - npm install
          - npm test
        services:
          - mongo
          - victoriaMetrics

definitions:
  services:
    mongo:
      image: mongo:3.6
    victoriaMetrics:
      image: victoriametrics/victoria-metrics:v1.75.1

I am trying to set up a bitbucket pipeline that uses a database service provided by a docker container. However, in order to get the database service started correctly, I need to pass an argument to be received by the database container's ENTRYPOINT. I see from the pipeline service doc that it's possible to send variables to the service's docker container, but the option I need to set isn't settable by an environment variable, only by a command line argument.

When I run the database's docker image locally using docker run, I am able to set the option just by adding it to the end of the docker run command, and it gets correctly applied to the container's ENTRYPOINT, so it seems like this should be straightforward, I just can't figure out where to put the argument in bitbucket-pipelines.yml.

Below is my bitbucket-pipelines.yml. Everything about it works great except that I need a way to pass a command line argument to the victoria-metrics container at the end of the file.

image: node:14.16.1
pipelines:
  default:
    - step:
        caches:
          - node
        script:
          - npm install
          - npm test
        services:
          - mongo
          - victoriaMetrics

definitions:
  services:
    mongo:
      image: mongo:3.6
    victoriaMetrics:
      image: victoriametrics/victoria-metrics:v1.75.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

压抑⊿情绪 2025-01-25 01:30:09

据 Atlassian 的 Mark C 称,目前有 无法将命令行参数传递给服务容器。不过,他为此功能创建了功能请求,欢迎您投票支持如果有兴趣。

同时,建议的解决方法是:

  1. 只要命令不受限制,您可以通过在 Pipelines 中运行 Docker 命令来启动服务容器。
    您可以检查 此链接了解有关管道上 Docker 限制命令的更多信息。
  2. 您可以创建自己的 Docker 映像(使用 Dockerfile)并将其上传到 Docker Hub,然后将该映像用作 Pipelines 上的服务容器

According to Mark C from Atlassian, there is presently no way to pass command line arguments to service containers. However, he has created a feature request for this capability, which you are welcome to vote for if interested.

In the meantime, the suggested workarounds are:

  1. You can start the service container by running a Docker command within Pipelines as long as the command is not restricted.
    You can check this link for more information about Docker restricted commands on Pipelines.
  2. You can create your own Docker image (using Dockerfile) and upload it to Docker Hub then use that image as a service container on Pipelines
來不及說愛妳 2025-01-25 01:30:09

这对我有用:

  default:
    - step:
        script:
          - ...
          - docker run -d --rm -p 27017:27017 mongo:latest mongod --replSet rs0 --bind_ip_all
          - ...
        services:
          - ...
          - docker
          - ...

This worked for me:

  default:
    - step:
        script:
          - ...
          - docker run -d --rm -p 27017:27017 mongo:latest mongod --replSet rs0 --bind_ip_all
          - ...
        services:
          - ...
          - docker
          - ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文