Alexander Mills
Alexander Mills

Reputation: 100090

What happens when you mv a folder that a docker container volume is using?

Say I run a container like so:

docker run -v /host/folder:/data some-image

if we run mv /host/folder /host/folder2, I am sure bad stuff will happen, and the only solution is to stop the container and restart it?

Upvotes: 3

Views: 797

Answers (1)

John Kugelman
John Kugelman

Reputation: 361749

Docker uses bind mounts a la mount --bind to make volumes available.

Bind mounts behave a lot like hard links. If you hard link foo to bar with ln foo bar, you can rename or remove foo and it won't affect bar because both files point to the same inode. Similarly, if you bind foo to bar with mount --bind foo bar, moving or removing foo/ won't affect bar/.

Let's take a look with two test directories foo and bar:

$ mkdir foo bar
$ touch foo/FOO bar/BAR
$ ls foo/
FOO
$ ls bar/
BAR

If we mount foo on top of bar and then rename foo, bar is unaffected:

$ sudo mount --bind foo bar
$ ls bar/
FOO
$ mv foo foo.renamed
$ ls bar/
FOO

Upvotes: 2

Related Questions