简体   繁体   English

将参数传递给 docker-compose.yml 中的图像

[英]Pass args to image in docker-compose.yml

Currently, my docker-compose.yml is building an image.目前,我的 docker-compose.yml 正在构建图像。 I have an image from a 3rd party that I need to add alongside my own, which my own image will be dependent on.我有来自第 3 方的图像,我需要将其与我自己的图像一起添加,我自己的图像将依赖于它。 When running the 3rd party image independently, I need to pass an argument to it like this:当独立运行第 3 方图像时,我需要向它传递一个参数,如下所示:

docker run third_party/image --argument_flag

How do I translate this into the docker-compose.yml so that the argument_flag gets passed.如何将其转换为 docker-compose.yml 以便通过 argument_flag。 Here is my yml (names have been generalized).这是我的 yml(名称已被概括)。

version: '3'
services:
  my_app:
    build: .
    volumes:
      - .:/my_app_folder
    depends_on: 
      - "third_party"
  third_party:
    image: third_party/image
    ports:
      - "8050:8050"

You can pass your argument by overriding the default command您可以通过覆盖默认命令来传递您的参数

In docker-compose file you can add like this.在 docker-compose 文件中,您可以像这样添加。 'args' tag in docker-compose file represent the argument same as docker run. docker-compose 文件中的“args”标签代表与 docker 运行相同的参数。

  third_party:
    image: third_party/image
    args:
       some_variable_name: some_value
    ports:
      - "8050:8050"

In Dockerfile you can get the argument ARGUMENT:在 Dockerfile 中,您可以获得参数 ARGUMENT:

docker-compose build --build-arg PRODUCTION=VALUE

Dockerfile: Dockerfile:

ARG ARGUMENT
FROM node:latest

or try to check it out: How to pass arguments within docker-compose?或尝试检查一下: How to pass arguments inside docker-compose? seems like the answer has been already there好像答案已经有了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM