moby icon indicating copy to clipboard operation
moby copied to clipboard

docker fails to mount the block device for the container on devicemapper

Open unclejack opened this issue 12 years ago • 391 comments

When running something like for i in {0..100}; do docker run busybox echo test; done with Docker running on devicemapper, errors are thrown and containers fail to run:

2014/02/10 9:48:42 Error: start: Cannot start container 56bee8c4da5bd5641fc42405c742083b418ca14ddfb4a3e632955e236e23c284: Error getting container 56bee8c4da5bd5641fc42405c742083b418ca14ddfb4a3e632955e236e23c284 from driver devicemapper: Error mounting '/dev/mapper/docker-8:1-4980769-56bee8c4da5bd5641fc42405c742083b418ca14ddfb4a3e632955e236e23c284' on '/var/lib/docker/devicemapper/mnt/56bee8c4da5bd5641fc42405c742083b418ca14ddfb4a3e632955e236e23c284': no such file or directory
2014/02/10 9:48:42 Error: start: Cannot start container b90b4385778142aab5251846460008e5c4eb9fe1e7ec82f07d06f1de823bd914: Error getting container b90b4385778142aab5251846460008e5c4eb9fe1e7ec82f07d06f1de823bd914 from driver devicemapper: Error mounting '/dev/mapper/docker-8:1-4980769-b90b4385778142aab5251846460008e5c4eb9fe1e7ec82f07d06f1de823bd914' on '/var/lib/docker/devicemapper/mnt/b90b4385778142aab5251846460008e5c4eb9fe1e7ec82f07d06f1de823bd914': no such file or directory
2014/02/10 9:48:43 Error: start: Cannot start container ca53b3b21c92ffb17ad15c1088be293260ea240abdf25db7e5aadc11517cf93c: Error getting container ca53b3b21c92ffb17ad15c1088be293260ea240abdf25db7e5aadc11517cf93c from driver devicemapper: Error mounting '/dev/mapper/docker-8:1-4980769-ca53b3b21c92ffb17ad15c1088be293260ea240abdf25db7e5aadc11517cf93c' on '/var/lib/docker/devicemapper/mnt/ca53b3b21c92ffb17ad15c1088be293260ea240abdf25db7e5aadc11517cf93c': no such file or directory
test
2014/02/10 9:48:43 Error: start: Cannot start container 1e1e06044711e73cede8ede10547de7e270c33fac7ad5e60a8cb23246950adf3: Error getting container 1e1e06044711e73cede8ede10547de7e270c33fac7ad5e60a8cb23246950adf3 from driver devicemapper: Error mounting '/dev/mapper/docker-8:1-4980769-1e1e06044711e73cede8ede10547de7e270c33fac7ad5e60a8cb23246950adf3' on '/var/lib/docker/devicemapper/mnt/1e1e06044711e73cede8ede10547de7e270c33fac7ad5e60a8cb23246950adf3': no such file or directory

Fedora 20 with kernel 3.12.9 doesn't seem to be affected.

kernel version, distribution, docker info and docker version:

3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64
Ubuntu 12.04.4
 docker info
Containers: 101
Images: 44
Driver: devicemapper
 Pool Name: docker-8:1-4980769-pool
 Data file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 3234.9 Mb
 Data Space Total: 102400.0 Mb
 Metadata Space Used: 6.9 Mb
 Metadata Space Total: 2048.0 Mb

Client version: 0.8.0-dev
Go version (client): go1.2
Git commit (client): 695719b
Server version: 0.8.0-dev
Git commit (server): 695719b
Go version (server): go1.2
Last stable version: 0.8.0

The Docker binary is actually master with PR #4017 merged.

/cc @alexlarsson

unclejack avatar Feb 10 '14 11:02 unclejack

Same here, running ubuntu precise with lts-raring kernel (3.8.0-35-generic).

discordianfish avatar Feb 11 '14 14:02 discordianfish

This is due to a race with udev. The problem is that starting a container creates a dm device, activates it and then immediately deactivates it and then activates it again. This races with the udev device-node creation such that you end up in a state where the device node created by udev is removed by docker.

alexlarsson avatar Feb 11 '14 17:02 alexlarsson

@alexlarsson Could we work around it somehow? It looks like every non-Fedora system has this problem.

unclejack avatar Feb 11 '14 17:02 unclejack

@unclejack https://github.com/dotcloud/docker/pull/4067 fixes it

alexlarsson avatar Feb 11 '14 17:02 alexlarsson

The problem seems to be fixed for runs, but not for builds. When building this Dockerfile:

FROM busybox
RUN  echo hello world

docker fails with the same error:

2014/02/12 03:30:52 build: Error getting container c9bfa29eaa875796895e6e1994b5437d983833da3249d4ea3337e3f560fab5af from driver devicemapper: Error mounting '/dev/mapper/docker-252:0-5767278-c9bfa29eaa875796895e6e1994b5437d983833da3249d4ea3337e3f560fab5af' on '/var/lib/docker/devicemapper/mnt/c9bfa29eaa875796895e6e1994b5437d983833da3249d4ea3337e3f560fab5af': no such file or directory

discordianfish avatar Feb 12 '14 11:02 discordianfish

@discordianfish I'll have a look at that.

alexlarsson avatar Feb 12 '14 12:02 alexlarsson

https://github.com/dotcloud/docker/pull/4096 fixes a similar spurious mount/unmount cycle during build.

alexlarsson avatar Feb 12 '14 15:02 alexlarsson

While the above fixes will fix this for most people we should probably leave this open to track the actual problem of the udev race, as it would be good to have a fix for that too.

alexlarsson avatar Feb 12 '14 15:02 alexlarsson

The above fixes are a big improvement, but when restarting container it sometimes still happens:

docker ps -q|xargs docker restart
Error: restart: Cannot restart container 3b96cdfee1eb: Error getting container 3b96cdfee1eb5e5b70d94d9a30e0c1cf9e9eba83901d63fd3e509df81cef8627 from driver devicemapper: Error mounting '/dev/mapper/docker-252:0-264246-3b96cdfee1eb5e5b70d94d9a30e0c1cf9e9eba83901d63fd3e509df81cef8627' on '/var/lib/docker/devicemapper/mnt/3b96cdfee1eb5e5b70d94d9a30e0c1cf9e9eba83901d63fd3e509df81cef8627': no such file or directory
Error: restart: Cannot restart container d968669da4ce: Error getting container d968669da4ce5632416e55fac56666c588e8ed236874394e9bbfa5e3561acb81 from driver devicemapper: Error mounting '/dev/mapper/docker-252:0-264246-d968669da4ce5632416e55fac56666c588e8ed236874394e9bbfa5e3561acb81' on '/var/lib/docker/devicemapper/mnt/d968669da4ce5632416e55fac56666c588e8ed236874394e9bbfa5e3561acb81': no such file or directory
96fd55c11524
6c0860bb723d

discordianfish avatar Feb 12 '14 15:02 discordianfish

@discordianfish The restart issue should be fixed in https://github.com/dotcloud/docker/pull/4180

alexlarsson avatar Feb 17 '14 15:02 alexlarsson

These issues aren't occurring any more on any of my test systems.

unclejack avatar Feb 21 '14 01:02 unclejack

I believe it is still possible to run into the race if you e.g. do: docker wait $id docker diff $if or something, where the container exits and we immediately start an operation that mounts it. However, the race is pretty small, so maybe its not possible in practice...

alexlarsson avatar Feb 21 '14 09:02 alexlarsson

Short description of what I believe is happening:

fish_: its a lot more complex fish_: both udev and docker are creating the nodes, and if this happens at the same time it gets into a weird situation where the device is activated but the device node doesn't exist something like: udev creates node we see it, so don't create we activate udev activates udev looks at the device, runs rules udev removes node => we're in a state where we activated and created the node, but the node is now gone

alexlarsson avatar Feb 21 '14 10:02 alexlarsson

Reopening still the actual problem is still there.

discordianfish avatar Mar 04 '14 17:03 discordianfish

Tentatively scheduling for 0.9.1

shykes avatar Mar 10 '14 17:03 shykes

There's still a problem with devicemapper. Using the script:

for i in {1..50}
do

CID=`docker run -d -P registry`
for j in {1..20}
do
docker kill $CID 2> /dev/null
docker restart $CID
done

docker kill $CID 2> /dev/null
docker rm $CID 2> /dev/null &

done

Docker ends up throwing an error which looks like this:

Error: Cannot restart container 3bb6ce8fa5b76b6c6c8bd2adcb20e473ca9b07b78d425a4dper/docker-8:1-1052351-3bb6ce8fa5b76b6c6c8bd2adcb20e473ca9b07b78d425a4dafcbccd66
2014/03/10 20:04:28 Error: failed to restart one or more containers

The environments on which this occurs are both running Ubuntu precise:

Ubuntu 12.04.4 LTS
Linux ubu1204-3 3.8.0-36-generic #52~precise1-Ubuntu SMP Mon Feb 3 21:54:46 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Linux ubu1204-2 3.11.0-17-generic #31~precise1-Ubuntu SMP Tue Feb 4 21:25:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

This is a problem on 0.8.1 and it's still a problem on 0.9.0. @alexlarsson Could this be the same udev race condition?

unclejack avatar Mar 10 '14 18:03 unclejack

We could try a workaround where we gratuitously keep a ref on a recently created device (unless you're trying to delete it) for say 1 second.

alexlarsson avatar Mar 12 '14 13:03 alexlarsson

I ran into another error which might or might not be related:

$ docker rm 5da32d8cfd63
Error: container_delete: Cannot destroy container 5da32d8cfd63: Driver devicemapper failed to remove root filesystem 5da32d8cfd63e59ad6f2dfdc189bdc62f3e25e8b6d90ac5407e485ce610e9001: UnmountDevice: no such device 5da32d8cfd63e59ad6f2dfdc189bdc62f3e25e8b6d90ac5407e485ce610e9001
2014/03/18 15:04:14 Error: failed to remove one or more containers

(Container is stopped for some weeks already, system was rebooted since that several times)

discordianfish avatar Mar 18 '14 16:03 discordianfish

@discordianfish That is https://github.com/dotcloud/docker/issues/4389

alexlarsson avatar Mar 18 '14 16:03 alexlarsson

@discordianfish And https://github.com/dotcloud/docker/pull/4499

alexlarsson avatar Mar 18 '14 16:03 alexlarsson