我想给(centos:6) Docker容器中的根用户一个.bashrc。然而,当我运行我的容器时,我发现.bashrc还没有源码。这可以做到吗?
我的build命令:
...
RUN touch .bashrc
RUN echo "iptables -t nat -A OUTPUT -d hostA -p tcp --dport 3306 -j DNAT --to hostB" >> .bashrc
...我的run命令:
docker run -it --cap-add=NET_ADMIN myImage /bin/bash发布于 2016-05-18 07:24:56
结果是我添加的文件不正确。它应该是/root/.bashrc,而不仅仅是.bashrc。将文件添加到正确的位置后,不需要运行命令或CMD。
构建
...
ADD iptables /iptables
RUN touch /root/.bashrc \
&& cat iptables >> /root/.bashrc
...跑
docker run -it --cap-add=NET_ADMIN myImage /bin/bash发布于 2016-05-18 05:38:06
bash manpage声明当shell是交互式的时,将读取.bashrc。因此,如果您想要一个读取.bashrc的bash,则需要使用-i启动bash。
请看:
root@host:~# echo 'echo this is .bashrc' > /tmp/bashrc
root@host:~# docker run -ti -v /tmp/bashrc:/root/.bashrc debian bash -i
this is .bashrc
root@01da3a7e9594:/#但是,在容器中像这样执行bash -i会覆盖入口点或cmd,因此最好将iptables命令和最初在成为入口点/ cmd的shell脚本中使用的入口点包装起来。
https://stackoverflow.com/questions/37284667
复制相似问题