Docker检查bash的历史logging

有人执行后:

docker exec -it ImageName /bin/bash exit 

我可以检查那个bash的历史吗?

我不认为docker image inspect是正确的命令在这里或docker history

问:有什么办法可以检查Docker容器的bash shell的历史吗?

答:可以。 当用户退出shell会话时,其历史logging将被写入一个名为.bash_history的文件,并位于用户的主目录中,在这种情况下是/root/.bash_history

访问内容的最简单方法之一是将文件作为卷挂载到主机上的另一个文件中。

例:

 touch container_bash_history docker run -v $(pwd)/container_bash_history:/root/.bash_history IMAGE_NAME 

您可能需要注意上面-v选项中指定的绝对文件path。 这是非常重要的,因为它向docker指出,挂载将作为单个文件挂载来完成,而不是通常的目录挂载。

您需要input已停止的容器(如果仍然存在)以获取其中的bash历史logging:

 # The only way is to first create an image from it docker commit $STOPPED_CONTAINER user/test_image # Then run a container based on the image to launch the `history` command inside it docker run --rm -ti user/test_image history 

资源