重用CLI中的docker环境variables
试想像这样有一个Dockerfile
FROM ubuntu:latest ENV HELLO_WORLD=hello CMD echo $HELLO_WORLD
我想从命令行重用这个variables:
> docker build -t hello . > docker run -e HELLO_WORLD='$HELLO_WORLD world' hello $HELLO_WORLD world
我想这会导致hello world
。
现在,我知道我可以在docker-compose和Dockerfile中做到这一点,但我不知道是否有机会从CLI中实现这种组合/重用?
编辑:所以我试图在docker-compose中实现同样的事情,我无法从容器中重用variables
> 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镜像中运行的可执行文件/脚本:(
ENV
指令在构build时使用,而不是在运行时使用。
如果你想坚持数据,写入一个文件。