问题描述
每次构建Docker容器时,命令历史记录(Ubuntu中的 + )都会丢失.有没有一种方法可以防止它在每次构建后重置历史记录?
Every time I build a Docker container, the command history (+ in Ubuntu) is lost. Is there a way to prevent it from resetting the history after each build ?
推荐答案
是的,有一种方法.即使有点棘手.
Yes, there is a way. Even though it's a little bit tricky.
基本上,除去容器时,将删除其整个文件系统.因此,您需要找到一些方法来保留命令历史记录文件.
Basically when a container is removed, its entire filesystem is erased. So you need to find some way to persist the command history file.
首先,在容器中找到外壳程序使用的历史记录文件.对我来说,我正在运行一个busybox容器.我发现历史记录文件是/root/ash_history
.
First, find the history file used by shell in the container. For me, I am running a busybox container. I find out the history file is /root/ash_history
.
$ ls -a /root
. .. .ash_history
然后,删除当前正在运行的容器,并在安装了主机文件的情况下重新运行它(以便我们可以持久保存/root/.ash_history
文件).
Then, remove currently running container and re-run it with a host file mounted (so that we can persist the /root/.ash_history
file).
docker run -v /path/to/host/file:/root/.ash_history ...
输入一些随机命令,然后删除容器并再次运行它,您将可以在容器中使用 + .
Input some random commands, and remove the container and run it again, you will be able to use + in the container.
这篇关于Docker:保留命令历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!