慶典

2017-09-08 246 views
1

有人經過的碼頭工人檢查歷史記錄執行:慶典

docker exec -it ImageName /bin/bash 
exit 

我可以檢查該慶典的歷史?

我不認爲docker image inspect是正確的命令在這裏或docker history

回答

1

您需要輸入停止容器(如果仍然存在),以獲得其內部的bash的歷史:

# 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 

Source

1

問:有什麼方法可以檢查docker容器的bash shell的歷史嗎?

- 答:是的,你可以。當用戶退出shell會話時,其歷史記錄將寫入名爲.bash_history的文件,並位於用戶的主目錄中,在此情況下爲/root/.bash_history

訪問其內容的最簡單方法之一是將文件作爲卷掛載到主機上的另一個文件。

例子:

touch container_bash_history 

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

你可能要注意這是在-v選項上面指定的絕對文件路徑。這一點非常重要,因爲它指示docker掛載將作爲單個文件掛載完成,而不是通常的目錄掛載。