How can I set PS1 environment variable (bash prompt) in Dockerfile?
I attempted ENV PS1 "\h:\W \u$ "
But this command does not change prompt.
I don't know why above ENV
does not set PS1 prompt.
How can I do it?
You can use docker run --env-file [path-toenv-file] to provide the environment variables to the container from a . env file.
Apart from the Dockerfile CMD directive and the docker run command, we can execute multiple commands with the docker-compose tool.
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.
For this reason, you can't mount a host directory from within the Dockerfile. The VOLUME instruction does not support specifying a host-dir parameter. You must specify the mountpoint when you create or run the container.
What is happening here is that PS1 is being redefined by the file ~/.bashrc
that is in your image and automatically sourced on start up of your container (it could be on another file - I am not sure if PS1 always get defined in ~/.bashrc on all linux distros).
Assuming it is defined in ~/.bashrc
, then you could write in your Dockerfile a RUN
command that could look like:
RUN echo PS1=\"\\h:\\W \\u$ \" >> ~/.bashrc
Et voila!
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