在运行脚本的docker容器之外访问bash脚本变量 [英] Access a bash script variable outside the docker container in which the script is running
本文介绍了在运行脚本的docker容器之外访问bash脚本变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在docker容器中运行的bash脚本.在此脚本中,我设置了一些变量的值.
I have a bash script running inside a docker container. In this script, I set the value of some variable.
我可以以某种方式在容器外部访问此变量的值吗?
我试图将变量设置为"global",但无法弄清楚该怎么做.将所需变量设置为容器内的环境变量是一个好主意吗?
I tried to make the variable "global" but could not figure out how to do it. Is it a good idea to make the required variable an environment variable inside the container?
如何复制
创建一个名为 temp.sh
的bash脚本,其内容如下:
Create a bash script called temp.sh
with the following contents:
a=$RANDOM
现在,按如下所示在docker容器中运行此文件:
Now, run this file in a docker container as follows:
docker run -it --rm -v $(pwd):/opt alpine sh -c "sh /opt/temp.sh"
所需行为:要能够在Docker容器外部访问变量 a
Desired behaviour: To be able to access the variable a
outside the docker container
推荐答案
查看全文