So i have this script that works fine in my host machine
#!/bin/bash -i
history > history.txt
but when i execute it in my docker container my history.txt looks like this : (it copies my script into the file and if i re-execute the script it does the same thing again !)
1 #!/bin/bash -i
2 history > history.txt
by the way when i execute "history > history.txt" directly from the terminal it works fine .
With bash -i
, executed lines are logged in the history. You execute lines from your script, therefore the lines from your script show up in history.txt
.
You can see this at the end of your history on the host as well:
$ tail -n 2 history.txt
29419 #!/bin/bash -i
29420 history > history.txt
In a clean Docker instance there is obviously no previous history, so those two lines are all you get:
$ tail -n 2 history.txt
1 #!/bin/bash -i
2 history > history.txt
There is no way to directly access your bash history outside of Docker from inside, so if that's what you want to do, you should dump it to a file first, and then give Docker access to this file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.