How to get a fancier bash prompt PS1 inside a docker container
Today I wanted to make a recording of me running some commands inside a docker-container.
❯ docker-compose run app bash root@e9bb2af4dc11:/usr/local/go/src/example.com/dev/project#
Needless to say it looked a bit bland with no colors and a long prompt that prevents me from recording a small terminal and show the full commands I'm typing clearly.
So here's the fancy prompt
🐳 a3382aa12c5e project #
- Cannot be done inside the Dockerfile, because not everyone in team will want this
- Cannot involve changes to files that are tracked by git, I don't want to accidentally check them in or deal with such a diff all the time
- Would be nice to have for all containers I start (Found no solution for this)
In my projects using docker I usually have the project folder mounted as a volume, which allows me to put some files inside the project which then become accessible from within the container.
But the prompt file should be easy to use for all my projects, so I put it among my dotfiles:
# ~/.docker-prompt PS1='🐳 \[\033[1;36m\]\h \[\033[1;34m\]\W\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]'
Then I copy the prompt file into the project
cp ~/.docker-prompt . since
symlinking did not work.
And then the file should be ignored by git globally
echo .docker-prompt >> ~/.gitignore_global
Now back inside the container we can load the propmt by simply doing
root@e9bb2af4dc11:/usr/local/go/src/example.com/dev/project# source .docker-prompt 🐳 a3382aa12c5e project # yay