Docker Community Forums

Share and learn in the Docker community.

Editing mounted _file_ with vim on host causes I/O error in vim


(Ash Berlin) #1

Expected behavior

Run this docker container

docker run -v $PWD/../lua-resty-letsencrypt/letsencrypt.lua:/etc/nginx/lualib/letsencrypt.lua -p 9080:80 -p 443:443 -ti --rm openresty sh

If you then edit this mounted file in vim, write it (:wq) then run this in the docker container

/ # ls -l /etc/nginx/lualib/letsencrypt.lua 
ls: /etc/nginx/lualib/letsencrypt.lua: I/O error

It shouldn’t do this :wink:


(Justin Cormack) #2

That may be fixable (cc @dsheets) but generally I would recommend mounting directories when editing, as most editors create temporary files in the same directory and move them atomically which will not work with a single file bind mounted as it is on a different file system mount point.


(David Sheets) #3

I’ve attempted to replicate this issue using https://github.com/torhve/lua-resty-letsencrypt and https://github.com/ficusio/openresty and editing with vi in the Alpine 3.3.1 environment of ficusio/openresty. I could not replicate the issue. Did you take any other actions in the container or involving Docker for Mac at the time? Was the letsencrypt.lua file on the default OS X HFS+ root volume at the time?

If you can reliably reproduce the issue, could you please run pinata diagnose -u after it occurs and post the output here?

Thanks for reporting the issue and participating in the Docker for Mac Beta! I’m sorry this issue affected you and we don’t have any leads, yet, on what the cause may be.


(Ash Berlin) #4

Yes I can reproduce regularly, on the default root partition.

Steps:

echo pre > foo
docker run --rm -ti -v $PWD/foo:/tmp/foo alpine:3.3 sh

In the container test it works:

# cat /tmp/foo
pre

Now edit in vim.

Then check in the container again:

/ # cat /tmp/foo
cat: can't open '/tmp/foo': I/O error

This might be particular to my vim config. If so you can “simulate” what vim is doing by running

rm foo; echo after2 > foo

I dont seem to have pinata command. Where does it come from?


(David Sheets) #5

Ah! I misunderstood and was editing the file in the container on the bind mount. I can reproduce reliably by editing on the host now. Sorry for the confusion.

I have ```
$ ls -l which pinata
lrwxr-xr-x 1 dsheets staff 67 Apr 6 15:40 /usr/local/bin/pinata -> /Users/dsheets/Library/Group Containers/group.com.docker/bin/pinata


but perhaps my machine is dirty. Anyway, running `pinata diagnose -u` is no longer necessary as I can reproduce the issue now.

Thanks for your report and participation in the Docker for Mac Beta! I'll let you know how this issue progresses.

(David Sheets) #6

Comparing with Docker on Linux (Ubuntu 15.10):

Editing with vi works correctly (write).
Editing with vim changes the inode and the bind mount does not update (rename) but no error occurs.

We’re going to work to align the Mac and Linux semantics but my advice is to bind mount the parent directory if you want editing of a bind mounted file to work correctly on either platform.

Thanks for your participation in the Docker for Mac Beta!