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?
My build command:
...
RUN touch .bashrc
RUN echo "iptables -t nat -A OUTPUT -d hostA -p tcp --dport 3306 -j DNAT --to hostB" >> .bashrc
...
My run command:
docker run -it --cap-add=NET_ADMIN myImage /bin/bash
The bash manpage states that
.bashrc
is read when the shell is interactive. Thus, if you want a bash that reads.bashrc
, you need to launch bash with-i
.See that:
But, executing
bash -i
like this in the container, overrides the entrypoint or cmd, so you might be better with wrapping the iptables command and the entrypoint you are originally using in a shell script that becomes your entrypoint / 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
Run