moby: unexpected file permission error in container
I’ve narrowed down a problem in an originally more involved setup. Consider the following Dockerfile:
# Dockerfile
FROM ubuntu:12.10
RUN apt-get install -y puppetmaster sudo
RUN rm -rf /etc/puppet
ADD puppet-config /etc/puppet
RUN chown -R puppet.puppet /etc/puppet
RUN chmod 755 /etc/puppet
When run with the following:
# make a dummy directory
mkdir puppet-config
echo "hi" >puppet-config/hello.txt
docker build -t dockbug .
echo "note the directory is owned by puppet with full read/write/execute privs"
docker run dockbug ls -al /etc/puppet
echo "but we get a permission error here"
docker run dockbug sudo -u puppet ls -al /etc/puppet
I see an unexpected permission error in the final command. This is with Docker 0.3.4 from the PPA on Ubuntu 13.04 with kernel 3.8.0-19-generic. Interestingly, if I remove the like “RUN rm -rf /etc/puppet” from the Dockerfile, I no longer see the permission error.
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 80 (41 by maintainers)
Commits related to this issue
- Fix bug due to docker/docker#783 — committed to swcc/docker-postgresql by deleted user 9 years ago
- Fix bug due to docker/docker#783 — committed to swcc/docker-postgresql by deleted user 9 years ago
- Fix bug due to docker/docker#783 — committed to swcc/docker-postgresql by deleted user 9 years ago
- Rename /build to /pd_build in order to work around an AUFS bug See https://github.com/docker/docker/issues/783 — committed to phusion/passenger-docker by FooBarWidget 9 years ago
- Add workaround for bug: https://github.com/docker/docker/issues/783#issuecomment-56013588 — committed to bgruening/docker-galaxy-stable by bgruening 9 years ago
- aufs: apply dirperm1 by default if supported Automatically detect support for aufs `dirperm1` option and apply it. `dirperm1` tells aufs to check the permission bits of the directory on the topmost b... — committed to dqminh/moby by dqminh 9 years ago
- document dirperm1 fix for #783 in known issues Since `dirperm1` requires a more recent aufs patch than many current OS release, we cant remove #783 completely. This documents that docker will apply `... — committed to dqminh/moby by dqminh 9 years ago
- document dirperm1 fix for #783 in known issues Since `dirperm1` requires a more recent aufs patch than many current OS release, we cant remove #783 completely. This documents that docker will apply `... — committed to jessfraz/docker by dqminh 9 years ago
- aufs: apply dirperm1 by default if supported Automatically detect support for aufs `dirperm1` option and apply it. `dirperm1` tells aufs to check the permission bits of the directory on the topmost b... — committed to jessfraz/docker by dqminh 9 years ago
- Changed dockerfile base image to debian. If the comment https://github.com/docker/docker/issues/783#issuecomment-55537066 is right, the issue being discussed there will stop here. Interesting is that... — committed to gavodachs/docker-dachs by chbrandt 9 years ago
- fix permission for aufs layer https://github.com/docker/docker/issues/783#issuecomment-19237045 — committed to jerep6/ogi by jerep6 8 years ago
- Add workaround for AUFS backend issue with postgresql PostgreSQL may fail at startup with /etc/ssl/private/ssl-cert-snakeoil.key permission denied. This is due to a limitation of the AUFS backend wh... — committed to guillon/docker-lava-server by guillon 8 years ago
- Add workaround for AUFS backend issue with postgresql Reorder layer commands in order to install ssl-cert in the first layer in order to avoid permission denied issue when starting postgresql on /etc... — committed to guillon/docker-lava-server by guillon 8 years ago
- Update Dockerfile to work around AUFS bug - https://github.com/docker/docker/issues/783 — committed to dcos/dcos-website by deleted user 8 years ago
- [dist] Workaround an aufs bug On some distributions bundler would fail with writing to the rubygem cache. This seems to be the aufs bug mentioned in moby/moby#783 Fixes #3940 — committed to hennevogel/open-build-service by hennevogel 7 years ago
- time to test whether but as per https://github.com/docker/docker/issues/783#issuecomment-56013588 is fixed with recent docker — committed to ARTbio/GalaxyKickStart by drosofff 6 years ago
We are seeing a very similar issue with Overlay.
Our current guess is that it is caused by the bug fixed in kernel 4.4.6 by this commit: https://lkml.org/lkml/2016/1/31/82
We have not yet managed to test with 4.4.6.
@jberkus thanks for the info. I was able to reproduce it on Ubuntu 14.04 on kernel 3.19.something. Would be nice to know which version of aufs its solved in, possibly the Docker Mac team can bump the version to include the patch that’s needed
rm /etc/puppet/*
didn’t work for me, instead I found that deleting individual files on the same layer works perfectly well:Here is link to my Gist
This is a kind of bug in AUFS. When a directory has a given permission mask in a lower layer, the upper layers cannot have a broader mask. Well, they can, but the more restrictive permission mask will be enforced anyways.
The rationale is the following:
Multiple behaviors could be considered “acceptable” in this scenario:
My understanding is that the last solution should be used, but for some reason, AUFS doesn’t behave correctly. It might be because the directory exists in a lower layer, then doesn’t exist anymore (because of the rm), then exists again (because of the ADD).
I’m willing to take a guess: the logic that decides whether or not to do a whiteout is not exactly the same as the one looking up permissions; so the first one stops when /etc/puppet is marked as non-existent in the middle layer, while the latter goes bottom up.
Anyway!
As a workaround, you can
rm /etc/puppet/*
instead ofrm /etc/puppet
, and that will do the trick.I opened an issue in the internal issue tracker as well (number
#2693
)I can confirm encountering this issue on the the docker os x beta-15 (current version). I have switched back to docker-machine in the meantime.
@antoineco I was able to reproduce on Docker for OS X, switching to overlay resolved it, so it’s an aufs issue indeed. Can you report this issue through beta-feedback@docker.com ?
Here’s a workaround I use in a postgres dockerfile
Just got bit by this too. We’ve got sequential builds, and at several points we need to obliterate a directory that was ADDed in a previous build step. I was surprised that the following command silently fails:
I’m not 100% sure why, but the workaround suggested by @jpetazzo above seems to work:
The only reason we have to do the “rm” in the first place is because the following line is really a
tar x
, and it leaves existing files around, as documented hereHmmm… What about a “KNOWN BUGS AND ISSUES” section in the documentation? /cc @metalivedev
@jpetazzo what do you think?
Since this is documented aufs behavior, we can 1) close this as wontfix, 2) close + document the behavior in the docker docs, or 3) other?
Labelling as aufs-related.