将bash命令历史记录(递归搜索命令)复制到Docker容器中

时间:2018-09-03 11:53:06

标签: bash docker dockerfile

我有一个正在交互使用的容器(create table #oneVariable (type int, amt int, bal int) insert #oneVariable values(10,10,20),(10,10,20),(20,10,20),(30,10,20) select type, sum(amt*bal) sumOfAmt_Bal from #oneVariable group by type -- type 10 has amt*bal 400. And, type 20 has 200. -- So according by you formula, Balance will be 200. -- Whereas, type 30 has been eliminated. declare @balance int SET @Balance = ( select sum( case type when 10 then amt * bal when 20 then -(amt * bal) end ) sumOfAmt_Bal from #oneVariable ) print @balance ),在其中,我必须运行一组相当通用的命令,尽管并非总是按设置的顺序进行,因此我不能只运行脚本。

因此,我想以一种方式在Docker容器中提供递归搜索docker run -it)中的命令。

有人知道我该怎么做吗?

1 个答案:

答案 0 :(得分:-1)

我在以下问题中找到了有用的信息:
Docker and .bash_history
Docker: preserve command history
https://superuser.com/questions/1158739/prompt-command-to-reload-from-bash-history

但是,它们使用docker卷挂载,这意味着容器命令会影响本地(主机PC)命令,我不希望这样做。

似乎我必须将~/.bash_history从本地复制到容器中,这将使历史记录“单向”工作。

更新:正在工作:
COPY your_command_script.sh some_folder/my_history
ENV HISTFILE myroot/my_history
RUN PROMPT_COMMAND="history -a; history -r"

说明
将命令脚本复制到容器中的文件中
告诉外壳查看历史记录的其他文件
重新加载历史文件