我有dockerfile
调用bash shell
执行命令来获取IP address
并将其存储到变量中。如何将变量的值从bash shell返回到dockerfile?在dockerfile
中返回变量后,如何在python
文件中访问该变量?
Dockerfile:
FROM mongo:3.0-wheezy
RUN apt-get update && apt-get install -y
WORKDIR /usr/src/mongodb
COPY . /usr/src/mongodb
## What I've tried ##
#CMD ['./script.sh']
#RUN bash 'export ip=`awk 'END{print $1}' /etc/hosts`'
ENV ip="bash 'export ip=`awk 'END{print $1}' /etc/hosts`'"
EXPOSE 27017
hello.py(样板代码):
mongoIP = os.environ.get('ip')
print(mongoIP)