Docker Compose - 使用容器环境变量的命令 [英] Docker Compose - Command using Container Environment Variable

查看:162
本文介绍了Docker Compose - 使用容器环境变量的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Docker编写将主服务器和从属服务器链接在一起。因此,从容器通过Compose自动注入包含连接到另一个主容器所需的各种端口和IP的环境变量。

Using Docker Compose to link a master and slave service together. The slave container is thus automatically injected by Compose with environment variables containing the various ports and IPs needed to connect to the other master container.

服务接受IP /主人通过命令行参数,所以我设置在我的命令

The service accepts the IP/Port of the master via a command line argument, so I set this in my commands.

master:
  command: myservice
  ports:
    - '29015'
slave:
  command: myservice --master ${MASTER_PORT_29015_TCP_ADDR}:${MASTER_PORT_29015_TCP_PORT}
  links:
    - master:master

问题是环境

启动群集时,会看到警告:警告:未设置MASTER_PORT_29015_TCP_ADDR变量。默认为空白字符串。

When starting the cluster - you see the warning: WARNING: The MASTER_PORT_29015_TCP_ADDR variable is not set. Defaulting to a blank string.

我尝试设置 entrypoint:[/ bin / sh,-c ] ,但是产生异常行为,其中服务根本看不到任何变量。 (有关信息,我实际使用的服务是RethinkDB)。

I tried setting entrypoint: ["/bin/sh", "-c"] but produced unusual behaviour where the service wouldn't see any variables at all. (For information, the service I'm actually using is RethinkDB).

推荐答案

如文档所述,链接环境变量现在不鼓励,您应该只写 master 而不是 $ MASTER_PORT_29015_TCP_ADDR 。而且,当你知道它的价值将是29015时,似乎没有任何意义写 $ MASTER_PORT_29015_TCP_PORT

As stated in the documentation, link environment variables are now discouraged, and you should just write master instead of $MASTER_PORT_29015_TCP_ADDR. Moreover, there doesn't seem to be any point to writing $MASTER_PORT_29015_TCP_PORT when you know its value's going to be 29015.

因此,将命令更改为:

myservice --master master:29015

这篇关于Docker Compose - 使用容器环境变量的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆