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.
Use -e or --env value to set environment variables (default []). If you want to use multiple environments from the command line then before every environment variable use the -e flag. Note: Make sure put the container name after the environment variable, not before that.
Docker has used the naming convention of ps from Linux; ps means 'process status' in Linux, and containers are actually running as a process on the Linux server; that's why 'docker ps' is used to list the containers.
ps means “Process Status”, so docker ps basically shows all of the Docker processes actively running. docker ps lists all containers that are up and running. -a means all (both stopped and running) containers.
This Dockerfile sets PS1
by doing:
RUN echo 'export PS1="[\u@docker] \W # "' >> /root/.bash_profile
I had the same problem but in docker-compose
context.
Here is how I managed to make it work:
# docker-compose.yml
version: '3'
services:
my_service:
image: my/image
environment:
- "PS1=$$(whoami):$$(pwd) $$ "
Just pass PS1 value as an environment variable in docker-compose.yml
configuration file.
Notice how dollars signs need to be escaped to prevent docker-compose
from interpolating values (documentation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With