Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set $PS1 with Dockerfile?

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?

like image 284
KiYugadgeter Avatar asked May 16 '16 12:05

KiYugadgeter


People also ask

Can you use an ENV file in a Dockerfile?

You can use docker run --env-file [path-toenv-file] to provide the environment variables to the container from a . env file.

Can I run 2 commands in Dockerfile?

Apart from the Dockerfile CMD directive and the docker run command, we can execute multiple commands with the docker-compose tool.

How do I pass an environment variable in Dockerfile?

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.

Can I mount volume in Dockerfile?

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.


1 Answers

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!

like image 155
Christophe Schmitz Avatar answered Oct 05 '22 23:10

Christophe Schmitz