【发布时间】:2017-05-13 03:21:46
【问题描述】:
我有一个 Dockerfile,它属于 Understand how CMD and ENTRYPOINT interact 中的矩阵中的 exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd 类别。这种行为不是我所期望的。我期待/bin/sh -c exec_cmd p1_cmd 先评估然后传递给exec_entry p1_entry。我观察到的是,/bin/sh -c exec_cmd p1_cmd 确实被传递到了exec_entry p1_entry,我认为这很有趣。
为了提供更多上下文,我专门从 existing Dockerfile 派生了一个新的 Dockerfile,其中父级具有:
ENTRYPOINT ["/bin/registrator"]
我想从我的 Dockerfile 中传递特定的命令行参数:
FROM gliderlabs/registrator:v7
CMD echo "-ip=$EXTERNAL_IP consul://$CONSUL_HOST"
当我在容器中运行 Docker 映像时:
$ docker run --rm --name=test-registrator --volume=/var/run/docker.sock:/tmp/docker.sock -e "EXTERNAL_IP=<some-ip>" -e "CONSUL_HOST=<some-consul-hostname>:8500" my/registrator
我收到以下错误:
2016/12/28 19:20:46 Starting registrator v7 ...
Extra unparsed arguments:
-c echo "-ip=$EXTERNAL_IP consul://$CONSUL_HOST"
Options should come before the registry URI argument.
Usage of /bin/registrator:
/bin/registrator [options] <registry URI>
-cleanup=false: Remove dangling services
-deregister="always": Deregister exited services "always" or "on-success"
-internal=false: Use internal ports instead of published ones
-ip="": IP for ports mapped to the host
-resync=0: Frequency with which services are resynchronized
-retry-attempts=0: Max retry attempts to establish a connection with the backend. Use -1 for infinite retries
-retry-interval=2000: Interval (in millisecond) between retry-attempts.
-tags="": Append tags for all registered services
-ttl=0: TTL for services (default is no expiry)
-ttl-refresh=0: Frequency with which service TTLs are refreshed
这意味着 -c echo "-ip=$EXTERNAL_IP consul://$CONSUL_HOST" 实际上是作为参数传递给 /bin/registrator。
我是在做错什么吗?或者这是对/bin/sh -c exec_cmd p1_cmd 在传递到ENTRYPOINT 之前没有先进行评估的用例的限制?如果后者是真的,那你能不能也解释一下这个用例的用处?
【问题讨论】:
标签: shell docker dockerfile consul registrator