docker exec interactive bash with init commands

For debugging I'd like to jump into any docker container I have and set a few niceties on my interactive bash shell off the bat. For some reason the --init-file style below is now working.

As with many things I imagine it's some escape sequence issue of sorts I'm missing. Any suggestions?

docker exec -it mycontainer bash --init-file <(echo "PS1='\w\$ '; TERM=xterm256; alias ls='ls -GFh'")

None of the commands in --init-file are applied to the bash shell launched in the container.


Solution 1:

Given your bash configuration in the file my-bash-niceties

#my-bash-niceties
PS1='\w\$ '
TERM=xterm256
alias ll='ls -GFh'

Option 1

One possibility is to mount the bash configuration file in your container...

docker run --detach -it -v `pwd`/my-bash-niceties:/etc/bashrc --name mycontainer bash:4.0

... and call bash using it as the init file.

docker exec -it  mycontainer bash  --init-file /etc/bashrc

Option 2

Another option is to mount your bash config file as your ~/.bashrc ...

docker run --detach -it -v `pwd`/my-bash-niceties:/root/.bashrc --name mycontainer bash:4.0

... and just exec bash in the container.

docker exec -it  mycontainer bash

In theory, the third (and best!) option, is just to mount the bash config file as /etc/profile.d/my_bash_rc.sh (any .sh file works), but I don't know why this container does not honor this convention. :(

btw, the option --init-file refers to a file inside the container's filesystem.