Customize docker container bash

I'm not sure using the ~/.profile configuration file is the best way to do what you want. Also, using RUN source /root/.profile won't have any effect since the line will be executed once only and won't be persistent when trying to execute the bash binary inside de container. (It will actually run a new bash session).

So.. first of all, the kind of configuration you are trying to do should be in the .bashrc file (Just because it is the place where it usually appear).

Then, as the bash man page say :

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order

And :

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.

What you should probably do :

In the Dockerfile :

COPY config/.bashrc /root/.bashrc

The .bashrc file you want to copy into your container is located in a config repo. This is where you should put you configuration.

Then, in the entrypoint :

exec "$@"

Then, you could run bash using the docker command :

docker run XXX /bin/bash

Tags:

Docker

Unix

Bash