I have a docker container and every time I build and start it, I want just to press UP for choosing a predefined command.

What's the best way to handle this?

$ echo "<yourcommand>" >> ~/.bash_history

or set up an alias in your .bashrc / .bash_aliases

alias s='<yourcommand(s)>' so every time you input s and hit enter it executes your commands.

  • Thx, I added your first suggestion in my Dockerfile and it works like a charm. It's so simple :) – Centin Mar 11 '16 at 7:47
  • For anyone who wants to keep the command out of the Dockerfile (because you only use it for dev, etc.), you can use bash -c to create the history / add the alias as shown in the answer. e.g., docker run -it ubuntu bash -c 'echo "<yourcommand>" >> ~/.bash_history && bash' – Chris Jul 19 '18 at 2:19

I do: : some_command

Then edit off the colon when I recall it in history. Colon is the null command. It used to be the way to comment things out before the hash became the comment character

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.