Docker TOTD

If you edit a Docker bind mounted file (-v sourcefile:destitnationfile) you may have recognized that you face a stale file handle under certain circumstances, especially if you edit the file with Vim on your Docker host.

This is because Vim will copy the content of the original edit file to a new one and after you save the changes, Vim exchanges this two files. The result of this operation is, that the inode of the file will be changed.

Docker uses the inode of the file for the bind mount and therefore, correctly, the file handle will be stolen after this operation.


Just open Vim without specifying the file. Afterwords type in :set backupcopy=yes and open the file you like to edit with :e yourfile. With this option you will edit the original file handle and not a copy.


Github issue


Mario Kleinsasser on GithubMario Kleinsasser on LinkedinMario Kleinsasser on Twitter
Mario Kleinsasser
Mario Kleinsasser
Doing Linux since 2000 and containers since 2009. Like to hack new and interesting stuff. Containers, Python, DevOps, automation and so on. Interested in science and I like to read (if I found the time). Einstein said "Imagination is more important than knowledge. For knowledge is limited." - I say "The distance between faith and knowledge is infinite. (c) by me". Interesting contacts are always welcome - nice to meet you out there - if you like, don't hesitate and contact me! - M