【发布时间】:2017-07-06 13:55:30
【问题描述】:
想象一下有一个像这样的 Dockerfile
FROM ubuntu:latest
ENV HELLO_WORLD=hello
CMD echo $HELLO_WORLD
我想从命令行重用这个变量:
> docker build -t hello .
> docker run -e HELLO_WORLD='$HELLO_WORLD world' hello
$HELLO_WORLD world
我希望这会产生hello world。
现在,我知道我可以在 docker-compose 和 Dockerfile 中做到这一点,但我想知道是否有机会从 CLI 实现这种组合/重用?
编辑: 所以我试图在 docker-compose 中实现相同的目标,但我无法重用容器中的变量
> cat docker-compose.yml
version: '2'
services:
hello:
image: 'hello'
environment:
- HELLO_WORLD="${HELLO_WORLD} world"
> docker-compose up hello
world
似乎只有 2 个地方可以访问 ENV,即 Dockerfile,然后是在该 docker 映像中运行的可执行文件/脚本 :(
【问题讨论】:
标签: docker command-line-interface