Skip to content

Instantly share code, notes, and snippets.

@zerok
Last active April 21, 2016 07:17
Show Gist options
  • Save zerok/79ba3842a475bb2d68b0c6767dc31781 to your computer and use it in GitHub Desktop.
Save zerok/79ba3842a475bb2d68b0c6767dc31781 to your computer and use it in GitHub Desktop.
Docker FS issue with mounted volumes

Hi 😊

We have run into a bit of a problem after upgrading to Docker 1.11 (also on new installations) where modifications of files inside a volume misbehave. Here is what we've tried:

  • Creating a new file inside the volume works from within the container -> OK
  • Deleting a file outside the container results in the file no longer being visible inside the container -> OK
  • Modifying an existing file from inside the container works but is only visible outside of the container -> BAD
  • Modifications made to an existing file outside the container are not visible inside the container -> BAD

Setups where we could reproduce this behaviour so far:

  • docker-machine 0.7.0, docker 1.11.0, OSX 10.11.4, VirtualBox 5.0.16 r105871

Setups where the operations behaved as expected:

  • Docker running on a native Linux host without Docker Machine in between
  • Docker for Mac (Version 1.11.0-beta7 (build: 5830) 8b45bc3afc0ca2363890032ac63b003d80ccc242)

The Docker file we've used to reproduce this looks like this:

FROM alpine

but we initially noticed this while using the official nginx image using jessie, hence we started to suspect it not being related to the used image.

After restarting the docker-machine it looks like a sync or flush takes places that changes the state of the volume again.

We have tried to provide a test case for reproducing part of this issue:

git clone https://gist.github.com/79ba3842a475bb2d68b0c6767dc31781.git
cd 79ba3842a475bb2d68b0c6767dc31781
docker build -t volume-bug .
docker run --rm -v $PWD:/opt volume-bug:latest

(Issue we created in the docker-machine project.)

FROM alpine
ADD run.sh /usr/local/bin/
VOLUME ["/opt"]
ENTRYPOINT ["/bin/sh", "/usr/local/bin/run.sh"]
#!/bin/sh
FILE=/opt/existing-file
CONTENT=`cat $FILE`
echo "Checking existing-file to see if it has still the original content."
if [[ "original" != "$CONTENT" ]]; then
echo "TAINTED TEST"
exit 1
fi
echo "Modifying existing-file to contain the word 'modified' instead of 'original'"
echo "modified" > $FILE
CONTENT=`cat $FILE`
echo "Checking if the file now contains the word 'modified'"
BROKEN=0
echo
if [[ "modified" == "$CONTENT" ]]; then
echo "EVERYTHING IS FINE"
else
echo "BROKEN! Got '$CONTENT' instead of 'modified'"
BROKEN=1
fi
# cleanup
echo "original" > $FILE
if [[ $BROKEN -eq 1 ]]; then
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment