如何在Docker中使用.bashrc作为root [英] How to .bashrc for root in Docker

查看:424
本文介绍了如何在Docker中使用.bashrc作为root的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给( centos:6 )Docker容器中的root用户一个 .bashrc 。但是,当我运行容器时,发现 .bashrc 尚未得到。可以做到吗?

I want to give my root user in a (centos:6) Docker container a .bashrc. However, when I run my container, I find that the .bashrc has not been sourced. Can this be done?

我的构建命令:

...
RUN touch .bashrc
RUN echo "iptables -t nat -A OUTPUT -d hostA -p tcp --dport 3306 -j DNAT --to hostB" >> .bashrc
...

我的运行命令:

docker run -it --cap-add=NET_ADMIN myImage /bin/bash


推荐答案

原来是我错误地添加了文件。它应该是 /root/.bashrc ,而不只是 .bashrc 。将文件添加到正确的位置,不需要运行命令或CMD。

Turns out I was adding the file incorrectly. It should be /root/.bashrc rather than just .bashrc. With the file added in the correct place, no run command or CMD is required.

Build

...
ADD iptables /iptables
RUN touch /root/.bashrc \
 && cat iptables >> /root/.bashrc
...

运行

docker run -it --cap-add=NET_ADMIN myImage /bin/bash

这篇关于如何在Docker中使用.bashrc作为root的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆