我需要在运行Docker Image时给出一个参数,该参数将是0-3之间的一个数字.
Dockerfile具有以下内容:
WORKDIR "mydir/build"
CMD ./maker oneapp > /artifacts/oneapp_$1.log ; ./maker twoapp > /artifacts/twoapp_$1.log ; ./maker -j13 threeapp > /artifacts/threeapp_$1.log
我将多次运行同一个Docker Image,因此需要将日志保存在/ artifacts中,并在适当时附加_0,_1,_2,_3.
我尝试将其保存在Docker文件中,但不想在运行docker时将整行作为参数传递.
ENTRYPOINT [“/bin/bash”]
./maker oneapp > /artifacts/oneapp_$1.log ; ./maker twoapp >
/artifacts/twoapp_$1.log ; ./maker -j13 threeapp >
/artifacts/threeapp_$1.log
是否有可能做到这一点?我需要在Dockerfile中修改什么才能做我想要的?
ENV suffix 0
./maker oneapp > /artifacts/oneapp_${suffix}.log
The environment variables set using
ENV
will persist when a container is run from the resulting image.
You can view the values usingdocker inspect
,and change them usingdocker run --env <key>=<value>
.
这样,您可以声明ENV
on docker run,并从运行容器中的值中受益.
the operator can set any environment variable in the container by using one or more -e flags,even overriding those mentioned above,or already defined by the developer with a Dockerfile ENV:
以您的情况为例:
docker run -e suffix=2 <image_name>