How to set PS1 in Docker Container

Raghu'nath Nandy picture Raghu'nath Nandy · Nov 1, 2014 · Viewed 10.5k times · Source

I want to set $PS1 environment variable to the container. It helps me to identify multilevel or complex docker environment setup. Currently docker container prompts with:

root@container-id# 

If I can change it as following , I can identify the container by looking at the $PS1 prompt itself.

[Level-1]root@container-id# 

I did experiments by exporting $PS1 by making my own image (Dockerfile), .profile file etc. But it's not reflecting.

Answer

user2915097 picture user2915097 · Nov 3, 2014

This Dockerfile sets PS1 by doing:

RUN echo 'export PS1="[\u@docker] \W # "' >> /root/.bash_profile