Save A Container's Bash History

Create Dockerfile

# Build from base image
FROM ubuntu:latest

Build Image From Dockerfile

Build the Dockerfile (docker build) in the current directory (.) and call the image chrisalbon/ubuntu:ubuntu (--tag chrisalbon/big-project:ubuntu).

docker build --tag chrisalbon/big-project:ubuntu .
Sending build context to Docker daemon  4.608kB
Step 1/1 : FROM ubuntu:latest
 ---> 1e4467b07108
Successfully built 1e4467b07108
Successfully tagged chrisalbon/big-project:ubuntu

Run Docker Container While Saving Bash History

Run container (docker run) called chrisalbon/big-project:ubuntu while connecting the container’s bash history (/root/.bash_history) with a file on the host machine (~/.containers_bash_history). Make it interative (-it). Run bash (/bin/bash).

docker run -v ~/.containers_bash_history:/root/.bash_history -it chrisalbon/big-project:ubuntu /bin/bash
[email protected]:/#

The container’s bash history will now be recorded on the host machine in ~/.containers_bash_history.